0.1.4 • Published 6 years ago
haskey v0.1.4
haskey
Checks for the existence of specified keys in an object
Installation
$ npm install haskey
Basic Usage
const user = {
name: 'willie',
last: 'm.i.k.'
};
const { pass, missing } = haskey(user)(['name', 'last']);
// pass : true
// missing: []
you may also use comma separated keys
const { pass, missing } = haskey(user)('name, last');
or whitespaced separated keys
const { pass, missing } = haskey(user)('name last');
or both
const { pass, missing } = haskey(user)('name,last email');
Common Usage Example
const otherUser = {
_id: 1
};
const { pass, missing } = haskey(otherUser)('name email last')
if (!pass) {
throw new Error(`user object missing: ${missing} keys`)
}
// pass: false
// missing: ['name', 'email', 'last']
// Error: user object missing name,email,last keys
License
Free software, Hell Yeah