1.0.2 • Published 6 years ago

get-props v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

get-props

gets exactly those property names that you need

Build Status NPM version

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) - if false only enumerable properties of obj will found.

  • protos (Boolean, default: false) - if true properties of objects (but not classes) in prototype chain of obj will found too.

  • symbols (Boolean, default: false) - if true properties of obj 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

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago

0.0.1

7 years ago