tonic example
parent
8a0719ea27
commit
833a234e4f
|
@ -0,0 +1,20 @@
|
|||
var Ajv = require('ajv');
|
||||
var ajv = Ajv({allErrors: true});
|
||||
|
||||
var schema = {
|
||||
"properties": {
|
||||
"foo": { "type": "string" },
|
||||
"bar": { "type": "number", "maximum": 3 }
|
||||
}
|
||||
};
|
||||
|
||||
var validate = ajv.compile(schema);
|
||||
|
||||
test({"foo": "abc", "bar": 2});
|
||||
test({"foo": 2, "bar": 4});
|
||||
|
||||
function test(data) {
|
||||
var valid = validate(data);
|
||||
if (valid) console.log('Valid!');
|
||||
else console.log('Invalid: ' + ajv.errorsText(validate.errors));
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ajv",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.2",
|
||||
"description": "Another JSON Schema Validator",
|
||||
"main": "lib/ajv.js",
|
||||
"files": [
|
||||
|
@ -35,6 +35,7 @@
|
|||
"url": "https://github.com/epoberezkin/ajv/issues"
|
||||
},
|
||||
"homepage": "https://github.com/epoberezkin/ajv",
|
||||
"tonicExampleFilename": ".tonic_example.js",
|
||||
"dependencies": {
|
||||
"json-stable-stringify": "^1.0.0"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue