ifonly

2.2.0 • Public • Published

ifonly

Build Status

ifonly is function that checks if your object have only and only specific properties you passed.

It works in both node and client-side applications.

Example

var obj;
 
obj = { a: 'a'};
console.log(only(obj, ['a'])); // true because only 'a' property is present
 
obj = { a: 'a', b: 'b', c: 'c' };
console.log(only(obj, ['a', 'b'])); // false because 'c' property is present
 
obj = { a: 'a' };
console.log(ifonly(obj, ['a', 'b'])); // false because 'b' does not exist
 
obj = { a: 'a', b: 'b', c: 'c' };
console.log(only(obj, ['a', 'b'], ['c'])); // true because 'c' property is ignored
 
obj = { a: '', b: 'b', c: '' };
console.log(only(obj, ['b'])); // true because 'a' and 'c' properties are empty
 
obj = { a: [], b: 'b', c: {} };
console.log(only(obj, ['b'])); // true because 'a' and 'c' properties are empty

Readme

Keywords

Package Sidebar

Install

npm i ifonly

Weekly Downloads

3

Version

2.2.0

License

MIT

Last publish

Collaborators

  • goschevski