New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

haskey

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haskey

Checks for existence of keys in object

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

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

Keywords

utility

FAQs

Package last updated on 23 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts