Socket
Socket
Sign inDemoInstall

ajv-formats

Package Overview
Dependencies
5
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ajv-formats

Plugin for AJV that adds support for some of draft2019 formats.


Version published
Weekly downloads
17M
decreased by-16.45%
Maintainers
1
Install size
1.21 MB
Created
Weekly downloads
 

Package description

What is ajv-formats?

The ajv-formats package provides support for string formats in JSON Schema validation using the AJV validator. It includes various string formats for date-time, email, hostname, ipv4, ipv6, uri, uri-reference, uuid, and more, which can be used to validate data against specific format requirements.

What are ajv-formats's main functionalities?

Date-time format validation

Validates that a string is a valid date-time representation according to the format specified in the JSON Schema.

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

Email format validation

Validates that a string is a valid email address.

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

URI format validation

Validates that a string is a valid URI.

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

UUID format validation

Validates that a string is a valid UUID.

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

Other packages similar to ajv-formats

Readme

Source

ajv-formats

Plugin for AJV that adds support for additional international formats and formats added in draft2019.

Currently, iri, iri-reference, idn-email, idn-hostname, and duration formats (added in draft 2019) are supported.

Installation

npm install ajv-formats

Usage

The main export is an apply function that patches an existing instance of ajv.

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

let schema = {
  type: 'string',
  format: 'idn-email'
};
ajv.validate(schema, 'квіточка@пошта.укр')  // returns true

Alternately, the formats can be passed as an option when creating a new ajv instance.

const Ajv = require('ajv');
const formats = require('ajv-formats/formats');
const ajv = new Ajv({formats});

let schema = {
  type: 'string',
  format: 'idn-email'
};
ajv.validate(schema, 'квіточка@пошта.укр')  // returns true

Draft07

The library also provides a draft07 export to load only the formats relevant to draft07.

const Ajv = require('ajv');
const formats = require('ajv-formats/draft07');
const 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.

idn-email

isemail 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.

FAQs

Last updated on 22 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc