npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medhira-ajv-utils

v0.1.0

Published

Custom AJV formats and keywords for validation - Powered by MEDHIRA

Readme


Why MEDHIRA AJV Utils?

Modern APIs need validation that goes beyond built-in JSON Schema types. medhira-ajv-utils extends AJV with production-ready formats and keywords so your schemas stay declarative and your application code stays clean.

| | | |---|---| | Ready-to-use formats | UUID, UTC timestamps, ISO 8601 durations, India-specific IDs | | Custom keywords | decimalPrecision for currency and numeric string rules | | TypeScript-first | Full type definitions shipped with the package | | Zero runtime dependencies | Pure validation logic — only AJV peer deps required |


Installation

npm install medhira-ajv-utils ajv ajv-formats ajv-errors
yarn add medhira-ajv-utils ajv ajv-formats ajv-errors

Requirements: Node.js 18+


Quick Start

import Ajv from 'ajv';
import ajvErrors from 'ajv-errors';
import ajvFormats from 'ajv-formats';
import { ajvCustomFormatsRegistry, ajvCustomKeywordsRegistry } from 'medhira-ajv-utils';

const ajv = new Ajv({ allErrors: true });

ajvErrors(ajv);
ajvFormats(ajv);
ajvCustomFormatsRegistry(ajv);
ajvCustomKeywordsRegistry(ajv);

const schema = {
  type: 'object',
  required: ['id', 'pan', 'amount'],
  properties: {
    id: { type: 'string', format: 'uuid' },
    pan: { type: 'string', format: 'india-PAN' },
    ifsc: { type: 'string', format: 'india-IFSC' },
    pincode: { type: 'string', format: 'india-pincode' },
    amount: { type: 'number', decimalPrecision: 2 },
  },
};

const validate = ajv.compile(schema);

const valid = validate({
  id: 'e3ced088-62a2-418b-bda1-d114a37badb3',
  pan: 'HNEPS8362B',
  ifsc: 'SBIN0001234',
  pincode: '516501',
  amount: 1500.5,
});

console.log('Valid:', valid);

Architecture

flowchart LR
    App["Your Application"] --> Ajv["Ajv Instance"]
    App --> MAU["medhira-ajv-utils"]
    MAU --> FmtReg["ajvCustomFormatsRegistry"]
    MAU --> KwReg["ajvCustomKeywordsRegistry"]
    FmtReg --> Ajv
    KwReg --> Ajv
    Ajv --> Schema["JSON Schema"]
    Schema --> Result["validate(data)"]

Available Formats

| Format | Description | Valid Example | Invalid Example | |--------|-------------|---------------|-----------------| | uuid | UUID (v1–v5) | e3ced088-62a2-418b-bda1-d114a37badb3 | e3ced088-62a2-418b-bda1-d114a | | india-PAN | Indian PAN (10 chars) | HNEPS8362B | PT12H | | india-Personal-PAN | Personal PAN (4th char P) | AAAPA1234A | HNEPS8362B | | india-IFSC | Indian IFSC code | SBIN0001234 | PT12H | | india-pincode | 6-digit PIN code | 516501 | 1234 | | udyam | Udyam registration ID | UDYAM-MH-12-1234567 | Udyam-12-34-1234567 | | positive-number-in-string | Non-negative number as string | 123, 0, 999.99 | -123, abc | | utc-date-time | UTC ISO 8601 timestamp | 2024-09-21T14:30:00Z | 12/09/2023 | | iso8601-duration | ISO 8601 duration | P13D, PT12H | 12 hours |

uuid

{ "type": "string", "format": "uuid" }

india-PAN

{ "type": "string", "format": "india-PAN" }

india-Personal-PAN

{ "type": "string", "format": "india-Personal-PAN" }

india-IFSC

{ "type": "string", "format": "india-IFSC" }

india-pincode

{ "type": "string", "format": "india-pincode" }

udyam

{ "type": "string", "format": "udyam" }

Format: UDYAM-XX-YY-ZZZZZZZXX = 2-letter state code, YY = 2-digit district code, ZZZZZZZ = 7-digit registration number.

positive-number-in-string

{ "type": "string", "format": "positive-number-in-string" }

utc-date-time

{ "type": "string", "format": "utc-date-time" }

Accepts timestamps with or without milliseconds (e.g. 2024-09-21T14:30:00Z or 2024-09-21T14:30:00.000Z).

iso8601-duration

{ "type": "string", "format": "iso8601-duration" }

Keywords

decimalPrecision

Enforces a maximum number of decimal places on number or numeric string values.

{
  "price": { "type": "number", "decimalPrecision": 2 }
}

| Value | decimalPrecision: 2 | |-------|----------------------| | 2, 2.11, "2.11" | Valid | | 2.123, "2.123", "2.123a" | Invalid |


Documentation

Full guides, API reference, and contributing docs:

https://medhira-ajv-utils.readthedocs.io/


Public API

This package intentionally exposes only two entry points:

| Export | Description | |--------|-------------| | ajvCustomFormatsRegistry(ajv) | Registers all custom formats on an AJV instance | | ajvCustomKeywordsRegistry(ajv) | Registers all custom keywords on an AJV instance |

Individual format and keyword modules are internal implementation details.


Contributing

Contributions are welcome! See Contributing Guide or open an issue on GitHub.

  1. Fork the repository
  2. Create a feature branch
  3. Add tests and update docs
  4. Submit a pull request

Sponsor & Support

To keep this library maintained and up-to-date, please consider sponsoring it on GitHub.

For private support or customization, reach out at [email protected]


About MEDHIRA

MEDHIRA — Engineering Intelligence Across Everything


License

Apache-2.0