ajv/README.md

53 lines
1.4 KiB
Markdown
Raw Normal View History

2015-05-30 01:32:47 +03:00
# ajv - Another JSON schema Validator
2015-05-20 03:55:53 +03:00
2015-05-30 01:22:11 +03:00
## TODO
- remote refs
2015-05-30 01:22:11 +03:00
- custom formats (via options)
- schema validation before compilation
- bundle compiled templates (doT will be dev dependency)
## Install
```
2015-05-30 01:32:47 +03:00
npm install ajv
2015-05-30 01:22:11 +03:00
```
## Usage
```
2015-05-30 01:32:47 +03:00
var ajv = require('ajv')(options);
var validate = ajv.compile(schema);
2015-05-30 23:08:31 +03:00
var valid = validate(data);
if (!valid) console.log(validate.errors);
2015-05-30 01:22:11 +03:00
```
or
```
2015-05-30 23:08:31 +03:00
// ...
var valid = ajv.validate(schema, data);
// ...
2015-05-30 01:22:11 +03:00
```
ajv compiles schemas to functions and caches them in both cases (using stringified schema as a key - using [json-stable-stringify](https://github.com/substack/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.
2015-05-30 01:22:11 +03:00
## Options
- _allErrors_: if true, ajv checks all rules collecting all errors, otherwise it will return after the first error (false by default)
- _verbose_: include the reference to the validated data in the errors (false by default)
- _format_: if false, the formats won't be validated (true by default)
- _uniqueItems_: if false, `uniqueItems` keyword will be ignored (true by default, i.e. uniqueItems is checked)
- _unicode_: if false, sting.length will be used and the string lengths with unicode pairs will be "incorrect" because each unicode pair will be counted as two characters (true by default - string lengths are calculated correctly but it is slower)
2015-06-05 23:37:36 +03:00
## Tests
```
git submodule update --init
npm test
```