mrkeyoor.com_
Sun 20 Sept 07:02 UTC
npmUtilsupdated 20 Sept 2026

ajv-formats review

ajv-formats 3.0.1 plugs the format vocabulary that Ajv 8 leaves outside its core validator back into an Ajv instance. After one registration call, schemas can check RFC 3339 dates and times, URI forms, email and host names, IPv4 and IPv6 addresses, UUIDs, JSON Pointers, regex syntax, and OpenAPI number or byte labels. It can also compare formatted date and time strings with formatMinimum and formatMaximum. Our install showed a small 100 KB package, although importing its complete format table produced a 125.2 KB minified browser bundle.

94.4Mdownloads / wk
Verdict

ajv-formats 3.0.1 installed in 0.8 seconds with 0 audit findings, but its full browser import measured 125.2 KB minified; it fits Ajv 8 services better than a page needing one email check. Install it for named JSON Schema formats and date comparisons, not as proof that an address or regex is safe.

We installed it

Lab card: what happened when we installed ajv-formatsScreenshot of ajv-formats documentation
Install✓ · 0.8s7 packages on disk · 4 MB
ImportESM import works · require() works · CommonJS package
Browser38.1 KBgzipped (125.2 KB minified), bundled with esbuild
TypesTypeScript types bundled
Known vulns00 critical · 0 high · 0 moderate · 0 low (npm audit)

Answers from our run

Does ajv-formats install cleanly?

Yes. In a fresh container with an empty cache, npm install ajv-formats finished in 0.8s, leaving 7 packages and 4 MB on disk. npm audit reported no known vulnerabilities.

How much does ajv-formats add to a browser bundle?

38.1 KB gzipped (125.2 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.

Does ajv-formats work with both ESM and CommonJS?

Yes. Both import 'ajv-formats' and require('ajv-formats') worked in Node 22 in our run. The package is published as CommonJS.

Does ajv-formats include TypeScript types?

Yes, type declarations ship inside the package, so no @types install is needed.

ajv-formats or ajv-formats-draft2019: which should you use?

ajv-formats-draft2019: Use it when schemas require IRI or internationalized email and hostname formats. ajv-formats 3.0.1 installed in 0.8 seconds with 0 audit findings, but its full browser import measured 125.2 KB minified; it fits Ajv 8 services better than a page needing one email check.

When should you not use ajv-formats?

The contract uses iri, iri-reference, idn-email, or idn-hostname. The README assigns those internationalized formats to ajv-formats-draft2019.

API stability5/5Version 3.0.1 still exposes one addFormats function, and the documented inputs remain an Ajv instance plus either a name list or a small options object. CommonJS require and ESM import both loaded that entry in our Node 22 check. The package declares Ajv ^8 as both its dependency and optional peer, which keeps the compatibility boundary explicit within the current major.
Docs3/5The official page enumerates every included format, identifies the 4 IDN and IRI omissions, documents full and fast modes, and explains all 4 comparison keywords with code. Exact expressions live in formats.ts, while strict-mode rules and wider JSON Schema behavior sit in the Ajv manual. The page also stops short of explaining the security limits of email and regex shape checks.
Maintenance2/5npm serves 3.0.1 without a deprecation flag, but GitHub records the last repository push on August 18, 2024 and currently groups 63 issues and pull requests as open. The repository is not archived. A narrow and settled API does not demand weekly releases, yet those dates and queue size are poor signals for a team waiting on a disputed format expression.
Ecosystem5/5The npm downloads endpoint counted 126,749,229 installations in the latest completed week. Ajv 8 is the required host, and our checks found bundled declarations plus working require and import paths. That reach makes the plugin easy to encounter through tools that already use Ajv, though it has no use with other validators and needs a companion package for internationalized formats.

Use it if

  • Ajv 8 compiles schemas that use email, uuid, date-time, hostname, uri, IP address, or JSON Pointer formats.
  • OpenAPI 3.0 documents bring int32, int64, float, double, byte, binary, or password format labels into your validation path.
  • A schema needs date or time bounds expressed with formatMinimum, formatMaximum, or their exclusive variants.
  • You want to load only named formats or trade full calendar checks for the simpler fast mode.
Skip it if

Setup reality

We installed ajv-formats 3.0.1 in a clean Node 22 Bookworm container. npm finished in 0.8 seconds, and the resulting 7 packages occupied 4 MB. The package lists 1 direct dependency and 1 peer dependency, is 100 KB unpacked, and includes its TypeScript declarations. npm audit found 0 known vulnerabilities. Both require() and ESM import worked even though this is CommonJS without an exports map.

Install Ajv in the same project, construct the Ajv 8 instance, and run addFormats before compiling a schema that names one of these formats. There are no accounts, environment variables, or config files. The dependency and peer ranges both point at Ajv 8, so a monorepo with several Ajv versions should check which instance receives the plugin.

The default full mode validates date and time ranges. Fast mode uses simpler expressions and, for dates and times, checks structure without checking calendar ranges. Registering a short name list leaves every other format unknown. Ajv strict mode then rejects schema compilation unless you explicitly map an ignored vendor format to true. When you pass an options object, set keywords: true if the schema uses the 4 comparison keywords.

Our whole-package esbuild check measured 125.2 KB minified and 38.1 KB gzipped. That is worth noticing in browser code that only needs one check. The date-time format demands a timezone, while iso-date-time permits one to be absent. IDN and IRI names live in another plugin, and regex validation says only that JavaScript can compile the pattern.

Patterns

Register the complete format set register-standard-formats

import Ajv from 'ajv';
import addFormats from 'ajv-formats';

const ajv = new Ajv();
addFormats(ajv);
const valid = ajv.compile({ type: 'string', format: 'email' });

Call addFormats before schema compilation; Ajv strict mode throws when a schema names an unknown format.

Register formats from CommonJS load-with-commonjs

const Ajv = require('ajv');
const addFormats = require('ajv-formats');
const ajv = new Ajv();
addFormats(ajv);

Version 3.0.1 is CommonJS without an exports map, and require() succeeded in our Node 22 sandbox.

Load only the formats a schema uses choose-formats

addFormats(ajv, ['uuid', 'date-time', 'ipv4']);
const validate = ajv.compile({ type: 'string', format: 'uuid' });

Any omitted format remains unknown and can stop compilation on a strict Ajv instance.

Use cheaper format checks select-fast-mode

addFormats(ajv, { mode: 'fast', formats: ['date', 'date-time', 'email'], keywords: true });

Fast mode does not check calendar ranges for date and time strings; it also simplifies URI and email expressions.

Validate an RFC 3339 date range bound-a-date

addFormats(ajv);
const validate = ajv.compile({
  type: 'string', format: 'date',
  formatMinimum: '2026-01-01',
  formatExclusiveMaximum: '2027-01-01'
});

Comparison keywords apply to strings and require a format with a comparison function.

Distinguish local and zoned timestamps allow-local-timestamp

addFormats(ajv, ['date-time', 'iso-date-time']);
const local = ajv.compile({ type: 'string', format: 'iso-date-time' });
const zoned = ajv.compile({ type: 'string', format: 'date-time' });

iso-date-time accepts a timestamp without a zone; date-time requires Z or a numeric offset.

Treat a vendor format as an annotation permit-vendor-format

const ajv = new Ajv({ formats: { 'account-code': true } });
addFormats(ajv);
const validate = ajv.compile({ type: 'string', format: 'account-code' });

Mapping a name to true prevents an unknown-format error and performs no value validation.

Override the email definition replace-email-check

addFormats(ajv);
ajv.addFormat('email', {
  type: 'string',
  validate: value => value.length <= 254 && /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(value)
});

Register the replacement after addFormats. A matching string still needs an ownership or delivery check.

Read OpenAPI integer labels validate-openapi-integers

addFormats(ajv, ['int32', 'int64']);
const validate = ajv.compile({ type: 'integer', format: 'int32' });

These names come from OpenAPI 3.0; JavaScript number values still have safe-integer limits.

Reject malformed regex text check-regex-source

addFormats(ajv, ['regex']);
const validate = ajv.compile({ type: 'string', format: 'regex' });
validate('[a-z]+');
validate('[');
validate('(a+)+$');

The final pattern compiles and therefore passes, even though running it against hostile input can be expensive.

Alternatives

PackageRegistryPick it when
ajv-formats-draft2019npmUse it when schemas require IRI or internationalized email and hostname formats.
zodnpmUse it for a TypeScript-first application that does not need portable JSON Schema documents.
joinpmUse it for a chainable Node validation API when standards-based schemas are not a requirement.

More utils guides

lru-cache · ajv · type-fest · p-limit · find-up · js-yaml · the whole shelf →

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.