1.0.6 • Published 5 years ago

ohas v1.0.6

Weekly downloads
15
License
MIT
Repository
github
Last release
5 years ago

has()

Build Status Coverage Status GitHub license NPM downloads GitHub issues

Determine if a javascript object has a key. Allows for nested key detection.

Installation

With yarn

yarn add ohas

With npm

npm install ohas --save

Usage

import has from 'ohas';

const user = {
  firstname: 'John',
  lastname: 'Smith',
  address: {
    street1: '123 Road Way Blvd',
    street2: 'APT 21',
    city: 'Brooklyn',
    state: 'NY'
  }
}

const hasFirstname = has(user, 'firstname');
console.log(hasFirstname); // true

const hasCity = has(user, 'address', 'city');
console.log(hasCity); // true

const hasZip = has(user, 'address', 'zip');
console.log(hasZip); // false

const hasUser2 = has(user2, 'firstname');
console.log(hasUser2); // false