main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
439 bytes
|
Rev | Line | |
---|
[d565449] | 1 | var Ajv = require('ajv');
|
---|
| 2 | var ajv = new Ajv({allErrors: true});
|
---|
| 3 |
|
---|
| 4 | var schema = {
|
---|
| 5 | "properties": {
|
---|
| 6 | "foo": { "type": "string" },
|
---|
| 7 | "bar": { "type": "number", "maximum": 3 }
|
---|
| 8 | }
|
---|
| 9 | };
|
---|
| 10 |
|
---|
| 11 | var validate = ajv.compile(schema);
|
---|
| 12 |
|
---|
| 13 | test({"foo": "abc", "bar": 2});
|
---|
| 14 | test({"foo": 2, "bar": 4});
|
---|
| 15 |
|
---|
| 16 | function test(data) {
|
---|
| 17 | var valid = validate(data);
|
---|
| 18 | if (valid) console.log('Valid!');
|
---|
| 19 | else console.log('Invalid: ' + ajv.errorsText(validate.errors));
|
---|
| 20 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.