RunKit + npm: xyjax-object-validator

node v10.24.1
endpointsharetweet
const { validate } = require('xyjax-object-validator') const validationConfig = { fieldsList: { must: ['a'] }, fieldsValues: { a: { must: [ {title: 'number', check: (x) => typeof(x) == 'number'}, {title: 'positive', check: (x) => x > 0} ], should: [ {title: '> 10', check: (x) => x > 10} ] } } } try { //error, 'a' is not positive validate(validationConfig)({a: 0, b: 1, c: 2}) } catch(e) { console.log(e) } try { //error, 'a' is not a number validate(validationConfig)({a: 'two', b: 1}) } catch(e) { console.log(e) } try { //error, there is no 'a' field validate(validationConfig)({b: 1, c: 2}) } catch(e) { console.log(e) } //warning - 'a' field is less than 10 validate(validationConfig)({a: 5}) //success validate(validationConfig)({a: 100})
Created from: https://npm.runkit.com/xyjax-object-validator
Loading…