Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.tonic_example.js 440B

1234567891011121314151617181920
  1. var Ajv = require('ajv');
  2. var ajv = new Ajv({allErrors: true});
  3. var schema = {
  4. "properties": {
  5. "foo": { "type": "string" },
  6. "bar": { "type": "number", "maximum": 3 }
  7. }
  8. };
  9. var validate = ajv.compile(schema);
  10. test({"foo": "abc", "bar": 2});
  11. test({"foo": 2, "bar": 4});
  12. function test(data) {
  13. var valid = validate(data);
  14. if (valid) console.log('Valid!');
  15. else console.log('Invalid: ' + ajv.errorsText(validate.errors));
  16. }