Urara-Blog/node_modules/.pnpm-store/v3/files/05/b16d40de439ed6b7abf5bb6f7ee117fe509e557c3abc35832fbefab57ad65fb09309eb42733080ee18ce55770d10330e054f83a57856624ed62a830397d11f
2022-08-14 01:14:53 +08:00

20 lines
No EOL
439 B
Text

var Ajv = require('ajv');
var ajv = new 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));
}