Registry / testing / ajv-formats-draft2019

ajv-formats-draft2019

JSON →
library1.6.1jsnpmunverified

Plugin for AJV (v1.6.1) adding draft2019 JSON Schema string formats: iri, iri-reference, idn-email, idn-hostname, and duration. Released regularly, supports cherry-picking formats for smaller bundles. Key differentiator: fills formats AJV core omits; provides internationalized formats for email and hostnames with RFC compliance (RFC 1123 vs older RFC 1034). Supports both patching an AJV instance or passing formats directly to constructor. Lightweight with minimal dependencies.

npm install ajv-formats-draft2019
INSTALL
IMPORT
SIG · AJV-FORMATS-DRAFT2
A
ajv-formats-draft2019
testingjavascriptv1.6.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

apply (default export)
import apply from 'ajv-formats-draft2019'
const { apply } = require('ajv-formats-draft2019')
Default export is the apply function. Using destructured require will yield undefined.
formats (named export from /formats)
import { formats } from 'ajv-formats-draft2019/formats'
const formats = require('ajv-formats-draft2019/formats')
This entrypoint provides a formats object for AJV constructor. Also supports named cherry-picking: import { duration, iri } from 'ajv-formats-draft2019/formats'.
idn (named export from /idn)
import { idn } from 'ajv-formats-draft2019/idn'
const idn = require('ajv-formats-draft2019/idn')
Exports only international formats: iri, iri-reference, idn-hostname, idn-email. Useful for reducing bundle size.

Patches an AJV instance with all draft2019 formats, then validates an international email.

import Ajv from 'ajv'; import apply from 'ajv-formats-draft2019'; const ajv = new Ajv(); apply(ajv); const schema = { type: 'string', format: 'idn-email' }; const valid = ajv.validate(schema, 'квіточка@пошта.укр'); console.log(valid); // true
Debug
Known issues
breakingv1.x requires AJV v8 or later; earlier AJV versions (v6, v7) are incompatible.
fix
Upgrade AJV to v8 or later, or use an older version of the package if on AJV v6/v7.
affects: >=1.0.0
gotchaDefault export is a function (apply), not a formats object. Mis-import causes undefined errors.
fix
Use correct import: import apply from 'ajv-formats-draft2019' and call apply(ajv).
affects: *
deprecatedUsing /formats entrypoint via require may be deprecated in future; prefer ESM imports.
fix
Switch to ESM import syntax: import { formats } from 'ajv-formats-draft2019/formats'.
affects: >=1.5.0
gotchaidn-email and idn-hostname implement RFC 1123, not RFC 1034 used in older JSON Schema drafts. This may cause strict validation differences.
fix
Be aware of the RFC difference; adjust test expectations accordingly.
affects: *
breakingCherry-picking formats with hyphens in name (e.g., idn-email) from /formats is not supported as named exports. Must use full formats object.
fix
Import the complete formats object or use the default apply function with options: { formats: ['idn-email'] }.
affects: *
Errors
Common errors & fixes
TypeError: apply is not a function
Default import used as named import: const { apply } = require('ajv-formats-draft2019');
fix
Use const apply = require('ajv-formats-draft2019'); (no destructuring).
Error: unknown format 'idn-email'
Formats not applied to AJV instance correctly, or format name misspelled.
fix
Ensure apply(ajv) is called before validation, or add format explicitly via options: { formats: ['idn-email'] }.
Module not found: Error: Can't resolve 'ajv-formats-draft2019/formats'
Missing entrypoint in older versions of the package (v<1.3.0).
fix
Upgrade to v1.3.0 or later; or use the default export directly.
ValidationError: data should match format 'idn-email'
Email string is not a valid international email according to RFC 1123 (e.g., missing TLD).
fix
Verify email conforms to RFC 5321/5322 with international characters; e.g., 'user@domain' is invalid, must have TLD.
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
ajvrequiredpeer dependency: required to use the formats plugin
Agent activity
45 hits · last 30 days
node
38
OpenAI (training)
1
Resources
ajv-formats-draft2019 — npm install ajv-formats-draft2019 · libregistry