get-props
v1.0.2
Published
gets exactly those property names that you need
Downloads
201
Readme
get-props
gets exactly those property names that you need
Install
npm i get-props
Usage
const getProps = require('get-props');
getProps(obj, options);
obj - object whose properties you want to receive
options - object with following fields:
enums (Boolean, default:
true
) - iffalse
only enumerable properties ofobj
will found.protos (Boolean, default:
false
) - iftrue
properties of objects (but not classes) in prototype chain ofobj
will found too.symbols (Boolean, default:
false
) - iftrue
properties ofobj
with symbol key will found too.
Returns array of property names.
Example
const s = Symbol();
const o1 = {};
o1[s] = 1;
const o2 = {};
Reflect.defineProperty(o2, 'notEnum', {enumerable: false, value: 1});
const F = function(){this.field = 1};
F.prototype.staticField = 1;
const o3 = new F();
Reflect.setPrototypeOf(o1, o2);
Reflect.setPrototypeOf(o2, o3);
console.log(getProps(o1, {protos: true, symbols: true}));
//[Symbol(""), "notEnum", "field"]
console.log(getProps(o1, {enums: false}));
//[]
License
MIT