Required-Keys
Make sure the desired key value pairs exist in a given object
Installation
npm install -S required-keys
Usage
Async
You must pass a callback where the error parameter will be null if there are no errors rk.truthy
var rk = ;var keys = 'foo' 'bar';var data = foo: false bar: 'test'rk;
rk.nonNull
var rk = ;var data = foo: false bar: 'test'var keys = 'foo' 'bar';rk;
rk.keysOnly
var rk = ;var data = foo: null bar: undefinedvar keys = 'foo' 'bar';rk;
Sync
All sync methods return null if all checks pass or an array of errors
rk.truthySync
var keys = 'dog' 'cat' 'lemon'var data = dog: 'dog' cat: 'cat' lemon: true apple: ''// err is either null if all keys map to truthy values or an array of errorsvar err = rk
rk.nonNullSync
var keys = 'dog' 'cat' 'lemon'var data = dog: 'dog' cat: 'cat' lemon: false// err is either null if all keys map to truthy values or an array of errorsvar err = rkshouldnot;
rk.keysOnlySync
var keys = 'dog' 'cat' 'lemon'var data = dog: null cat: undefined fruit: 'banana'// err is either null if all keys map to truthy values or an array of errorsvar err = rk