Plugin for AJV that adds support for some of string formats adding in the draft2019 JSON Schema.
Installations
npm install ajv-formats-draft2019
Releases
Unable to fetch releases
Developer
luzlab
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
12.20.1
NPM Version
7.16.0
Statistics
10 Stars
66 Commits
8 Forks
4 Watching
5 Branches
6 Contributors
Updated on 22 Oct 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
14,775,180
Last day
-5%
37,890
Compared to previous day
Last week
3.9%
207,316
Compared to previous week
Last month
10.8%
847,287
Compared to previous month
Last year
88.3%
8,216,440
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
ajv-formats-draft2019
An AJV plugin adding support for draft2019 formats missing from AJV.
Currently, iri
, iri-reference
, idn-email
, idn-hostname
, and duration
formats are supported. duration
was added in draft 2019. The uuid
format was
added in draft2019, but is already supported by the ajv-formats
package.
Using international formats with pre-draft2019 JSON schemas
The idn-email
and idn-hostname
formats are implemented per RFC 1123, however
earlier JSON schemas specify RFC 1034. This is probably just fine, but you have
been warned...
Installation
1npm install --save ajv-formats-draft2019
Usage
The default export is an apply
function that patches an existing instance of
ajv
.
1const Ajv = require('ajv'); 2const apply = require('ajv-formats-draft2019'); 3const ajv = new Ajv(); 4apply(ajv); // returns ajv instance, allowing chaining 5 6let schema = { 7 type: 'string', 8 format: 'idn-email', 9}; 10ajv.validate(schema, 'квіточка@пошта.укр'); // returns true
The apply
function also accepts a second optional parameter to specify which
formats to add to the ajv
instance.
1const Ajv = require('ajv'); 2const apply = require('ajv-formats-draft2019'); 3const ajv = new Ajv(); 4 5// Install only the idn-email and iri formats 6apply(ajv, { formats: ['idn-email', 'iri'] });
The module also provides an alternate entrypoint ajv-formats-draft2019/formats
that works with the ajv
constructor to add the formats to new instances.
1const Ajv = require('ajv'); 2const formats = require('ajv-formats-draft2019/formats'); 3const ajv = new Ajv({ formats }); 4 5let schema = { 6 type: 'string', 7 format: 'idn-email', 8}; 9ajv.validate(schema, 'квіточка@пошта.укр'); // returns true
Using the ajv-formats-draft2019/formats
entry point also allows cherry picking
formats. Note the approach below only works for formats that don't contain a
hypen -
in the name. This approach may yield smaller packed bundles since it
allows tree-shaking to remove unwanted validators and related dependencies.
1const Ajv = require('ajv'); 2const { duration, iri } = require('ajv-formats-draft2019/formats'); 3const ajv = new Ajv({ formats: { duration, iri } });
International formats
The library also provides an idn
export to load only the international formats
(ie. iri
, iri-reference
, idn-hostname
and idn-email
).
1const Ajv = require('ajv'); 2const formats = require('ajv-formats-draft2019/idn'); 3const ajv = new Ajv({ formats });
Formats
iri
The string is parsed with 'uri-js' and the scheme is checked against the list of
known IANA schemes. If it's a 'mailto' schemes, all of the to:
addresses are
validated, otherwise we check there IRI includes a path and is an absolute
reference.
iri-reference
All valid IRIs are valid. Fragments must have a valid path and of type "relative", "same-document" or "uri". If there is a scheme, it must be valid.
Validating a IRI references is challenging since the syntax is so permissive. Basically, any URL-safe string is a valid IRI syntactically. I struggled to find negative test cases when writing the unit tests for IRI-references. Consider:
google.com
is NOT a valid IRI because it does not include a scheme.file.txt
is a valid IRI-reference/this:that
is a valid IRI-referencethis:that
is a NOT a valid IRI-reference
idn-email
smtp-address-parser
is
used to check the validity of the email.
idn-hostname
The hostname is converted to ascii with punycode and checked for a valid tld.
duration
The string is checked against a regex.
Releases
v1.6.1
- Updated
schemes
dependency, adding support formodbus+tcp
andmqtt
in URIs.
v1.6.0
- Fix tests to work with AJV v7+ and how
ajv
is exported, rather than changes to this library.
v1.5.0
- Upgrade dependencies
v1.4.4
- The last release that's compatible with Node 8.
- Fixed a bug when validated
mailto:
IRIs.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/luzlab/ajv-formats-draft2019/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/luzlab/ajv-formats-draft2019/node.js.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 4/14 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 24 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More