checkin
Lint option and merge with default value
Getting Started
$ npm install --save-dev checkin
const option = filename: 'test.png' size: '20' tag: 'icon'const lint = filename: typeOf: 'string' isRequire: true size: typeOf: 'number' Numberval within: 1 20 tag: def: 'icon' oneOf: 'icon' 'human' color: def: 'red' typeOf: 'string' 'number' const expected = //=> { filename: 'test.png', size: 20, size: 20, color: 'red' }
Rules
coerce
Return a new value by given function.
const obj = foo: 1 const lint = foo: val + 1 const expected = // => { foo: 2 }
default (alias: def)
Return a default value when the key is undefined.
const obj = {}const lint = foo: default: 1 const expected = // => { foo: 1 }
equal
Check by deep equal.
const obj = foo: 1 const lint = foo: equal: 1 const expected = // => { foo: 1 }
const obj = foo: 1 const lint = foo: equal: 2 const expected = // => throw AssertionError: expected foo to to be equal to 2
oneOf
const obj = foo: 1 const lint = foo: oneOf: 1 2 const expected = // => { foo: 1 }
const obj = foo: 1 const lint = foo: oneOf: 3 const expected = // => throw AssertionError: expected foo to to be one of Array [ 3 ]
required
Check if the parameter is defined.
const obj = foo: 1 const lint = foo: required: true const expected = // => { foo: 1 }
satisfy
Check if the parameter is satifsy to the given function.
const obj = foo: 1 const lint = foo: val > 0 const expected = // => { foo: 1 }
typeOf
const obj = foo: 1 const lint = foo: typeOf: 'string' 'number' const expected = // => { foo: 1 }
within
const obj = foo: 1 const lint = foo: within: 0 2 const expected = // => { foo: 1 }
Test
$ npm i && npm test
License
MIT