tonic example

master
Evgeny Poberezkin 2015-11-28 22:39:50 +00:00
parent 8a0719ea27
commit 833a234e4f
2 changed files with 22 additions and 1 deletions

20
.tonic_example.js Normal file
View File

@ -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));
}

View File

@ -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"
},