This package has been deprecated

Author message:

Package has been moved to keycheck 0.0.1

haskey
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

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

MIT

Free software, Hell Yeah

Readme

Keywords

Package Sidebar

Install

npm i haskey

Weekly Downloads

1

Version

0.1.4

License

MIT

Unpacked Size

101 kB

Total Files

7

Last publish

Collaborators

  • m8r1x