0.2.3 • Published 7 years ago
object-has-keys v0.2.3
object-has-keys 
A JavaScript utility to check if given object has a set of keys.
Getting started
The first step is to add object-has-keys into your project.
$ npm install --save object-has-keysUsage
Import the package into your package using require or import statements
const { hasKeys, hasAnyKey } = require('object-has-keys'); // CommonJSimport { hasKeys, hasAnyKey } from 'object-has-keys'; // ES2015+The hasKeys function takes two arguments, the object and the keys. It returns true if all the keys queried exist.
const myObject = {
key1: 'value',
key2: 'value',
key3: 'value'
};
hasKeys(myObject, 'key1'); // true
hasKeys(myObject, ['key1', 'key2']); // true
hasKeys(myObject, 'key5'); // false
hasKeys(myObject, ['key5']); // false
hasKeys(myObject, ['key1', 'key5']); // falseThe hasAnyKey function takes two arguments, the object and the keys. It returns true if any key queried exists.
const myObject = {
key1: 'value',
key2: 'value',
key3: 'value'
};
hasAnyKey(myObject, 'key1'); // true
hasAnyKey(myObject, ['key1', 'key5']); // true
hasAnyKey(myObject, 'key5'); // false
hasAnyKey(myObject, ['key6']); // falseContributing
To contribute, follow one of the two options:
Open an Issue
Open an issue detailing:
- What the issue is
- Steps to reproduce
- Possible solutions
Note: These details are recommended but are entirely optional.
Send a Pull Request
Fork this project and send a pull request to the
masterbranch.
License
MIT