JSONSchema handling / validator
npm install jema.jsjavascript
const schema = new Schema({
type: 'string',
minLength: 3,
pattern: '^[a-zA-Z]+$',
});
await schema.deref(); // Dereference remote schemas
schema.validate('Li') // false
schema.validate('Liam') // true
schema.validate('Li-Am') // false
`
Install
`javascript
import {Schema} from 'https://cdn.jsdelivr.net/gh/nuxodin/jema.js@x.x.x/schema.min.js';
`
Debugging
`javascript
// errors
const errors = schema.errors('L-')
for (const error of errors) {
console.log(error.message)
// "L-" does not match minLength:3
// "L-" does not match pattern:^[a-zA-Z]+$
}
// schema validation
const schema = new Schema({
type: 'stringg',
});
await schema.schemaErrors();
``