object-valid
tiny deep object validation library
usage
npm install object-valid
var validate = /****************************************************************************** define type tester******************************************************************************/var spec_Ax = { return true } // property x must exist, but can be anything var spec_Ay = y: { return typeof x === 'boolean'} { return typeof x === 'number'} { return typeof x === 'string'} { return typeof x === 'object' && x !== null } { return typeof x === 'function'} a: ArrayisArray // type is function name { return x === undefined } { return x === null } var spec_B = x: y: { return Array && xlength > 3 } { return true } var typeAx = var typeAy = var typeB = /****************************************************************************** some objects******************************************************************************/var A = x: undefined y: b: false x: 0 z: '' o: {} {} a: n: null u: undefined var B = x : y: z: 1234 {}/****************************************************************************** validate objects******************************************************************************/ // throws if object doesnt pass specification // throws if object doesnt pass specification // throws if object doesnt pass specification
related
- x-is can be used to define an object spec