UNPKG

bs-ajv

Version:

BucklesScript bindings to Ajv (Another JSON Validator)

23 lines (22 loc) 517 B
/* just an exercise to see what the interface to Ajv is like */ const Ajv = require('ajv'); const ajv = new Ajv; const validate_me = { "message": "eug" }; const schema = { "title": "Message", "type": "object", "properties": { "message": { "type": "string", "maxLength": 3, "pattern": "^(e.*|)$" } }, "required": [ "message" ] }; const validate = ajv.compile(schema); const valid = validate(validate_me); console.log('valid=', valid); console.log('errors=', validate.errors);