basant307/AI_Governance_Project
048
1# ajv-formats2 3JSON Schema formats for Ajv4 5[](https://travis-ci.org/ajv-validator/ajv-formats)6[](https://www.npmjs.com/package/ajv-formats)7[](https://gitter.im/ajv-validator/ajv)8[](https://github.com/sponsors/epoberezkin)9 10## Usage11 12```javascript13// ESM/TypeScript import14import Ajv from "ajv"15import addFormats from "ajv-formats"16// Node.js require:17const Ajv = require("ajv")18const addFormats = require("ajv-formats")19 20const ajv = new Ajv()21addFormats(ajv)22```23 24## Formats25 26The package defines these formats:27 28- _date_: full-date according to [RFC3339](http://tools.ietf.org/html/rfc3339#section-5.6).29- _time_: time (time-zone is mandatory).30- _date-time_: date-time (time-zone is mandatory).31- _iso-time_: time with optional time-zone.32- _iso-date-time_: date-time with optional time-zone.33- _duration_: duration from [RFC3339](https://tools.ietf.org/html/rfc3339#appendix-A)34- _uri_: full URI.35- _uri-reference_: URI reference, including full and relative URIs.36- _uri-template_: URI template according to [RFC6570](https://tools.ietf.org/html/rfc6570)37- _url_ (deprecated): [URL record](https://url.spec.whatwg.org/#concept-url).38- _email_: email address.39- _hostname_: host name according to [RFC1034](http://tools.ietf.org/html/rfc1034#section-3.5).40- _ipv4_: IP address v4.41- _ipv6_: IP address v6.42- _regex_: tests whether a string is a valid regular expression by passing it to RegExp constructor.43- _uuid_: Universally Unique IDentifier according to [RFC4122](http://tools.ietf.org/html/rfc4122).44- _json-pointer_: JSON-pointer according to [RFC6901](https://tools.ietf.org/html/rfc6901).45- _relative-json-pointer_: relative JSON-pointer according to [this draft](http://tools.ietf.org/html/draft-luff-relative-json-pointer-00).46- _byte_: base64 encoded data according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)47- _int32_: signed 32 bits integer according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)48- _int64_: signed 64 bits according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)49- _float_: float according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)50- _double_: double according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)51- _password_: password string according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)52- _binary_: binary string according to the [openApi 3.0.0 specification](https://spec.openapis.org/oas/v3.0.0#data-types)53 54See regular expressions used for format validation and the sources that were used in [formats.ts](https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts).55 56**Please note**: JSON Schema draft-07 also defines formats `iri`, `iri-reference`, `idn-hostname` and `idn-email` for URLs, hostnames and emails with international characters. These formats are available in [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) plugin.57 58## Keywords to compare values: `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum`59 60These keywords allow to define minimum/maximum constraints when the format keyword defines ordering (`compare` function in format definition).61 62These keywords are added to ajv instance when ajv-formats is used without options or with option `keywords: true`.63 64These keywords apply only to strings. If the data is not a string, the validation succeeds.65 66The value of keywords `formatMaximum`/`formatMinimum` and `formatExclusiveMaximum`/`formatExclusiveMinimum` should be a string or [\$data reference](https://github.com/ajv-validator/ajv/blob/master/docs/validation.md#data-reference). This value is the maximum (minimum) allowed value for the data to be valid as determined by `format` keyword. If `format` keyword is not present schema compilation will throw exception.67 68When these keyword are added, they also add comparison functions to formats `"date"`, `"time"` and `"date-time"`. User-defined formats also can have comparison functions. See [addFormat](https://github.com/ajv-validator/ajv/blob/master/docs/api.md#api-addformat) method.69 70```javascript71require("ajv-formats")(ajv)72 73const schema = {74 type: "string",75 format: "date",76 formatMinimum: "2016-02-06",77 formatExclusiveMaximum: "2016-12-27",78}79 80const validDataList = ["2016-02-06", "2016-12-26"]81 82const invalidDataList = ["2016-02-05", "2016-12-27", "abc"]83```84 85## Options86 87Options can be passed via the second parameter. Options value can be88 891. The list of format names that will be added to ajv instance:90 91```javascript92addFormats(ajv, ["date", "time"])93```94 95**Please note**: when ajv encounters an undefined format it throws exception (unless ajv instance was configured with `strict: false` option). To allow specific undefined formats they have to be passed to ajv instance via `formats` option with `true` value:96 97```javascript98const ajv = new Ajv((formats: {date: true, time: true})) // to ignore "date" and "time" formats in schemas.99```100 1012. Format validation mode (default is `"full"`) with optional list of format names and `keywords` option to add additional format comparison keywords:102 103```javascript104addFormats(ajv, {mode: "fast"})105```106 107or108 109```javascript110addFormats(ajv, {mode: "fast", formats: ["date", "time"], keywords: true})111```112 113In `"fast"` mode the following formats are simplified: `"date"`, `"time"`, `"date-time"`, `"iso-time"`, `"iso-date-time"`, `"uri"`, `"uri-reference"`, `"email"`. For example, `"date"`, `"time"` and `"date-time"` do not validate ranges in `"fast"` mode, only string structure, and other formats have simplified regular expressions.114 115## Tests116 117```bash118npm install119git submodule update --init120npm test121```122 123## License124 125[MIT](https://github.com/ajv-validator/ajv-formats/blob/master/LICENSE)126 