Package Exports
- ajv
- ajv/lib/ajv
- ajv/lib/compile/equal
- ajv/lib/compile/formats
- ajv/lib/compile/formats.js
- ajv/lib/refs/json-schema-draft-04
- ajv/lib/refs/json-schema-draft-04.json
- ajv/package.json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ajv) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ajv - Another JSON schema Validator
One of the fastest JSON schema validators. It uses doT templates to generate super-fast validating functions.
TODO
- remote refs
- custom formats (via options)
- schema validation before compilation
- bundle compiled templates (doT will be dev dependency)
Install
npm install ajv
Usage
var ajv = require('ajv')(options);
var validate = ajv.compile(schema);
var valid = validate(data);
if (!valid) console.log(validate.errors);
or
// ...
var valid = ajv.validate(schema, data);
// ...
ajv compiles schemas to functions and caches them in both cases (using stringified schema as a key - using json-stable-stringify), so that the next time the same schema is used (not necessarily the same object instance) it won't be compiled again.
Options
- allErrors: check all rules collecting all errors. Default is to return after the first error.
- verbose: include the reference to the validated data in the errors.
- format: validate formats (true by default).
- uniqueItems: validate
uniqueItems
(true by default). - unicode: calculate correct length of strings with unicode pairs (true by default - string lengths are calculated correctly but it is slower). Pass
false
to usestring.length
that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters. - beautify: format the generated function with js-beautify.
npm install js-beautify
to use this option.
Tests
git submodule update --init
npm test