Skip to content

Commit

Permalink
ignore non-enumerable properties - fixes sindresorhus#23
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Mar 27, 2016
1 parent c06a56f commit 2c301fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module.exports.get = function (obj, path) {
var pathArr = getPathSegments(path);

for (var i = 0; i < pathArr.length; i++) {
var descriptor = Object.getOwnPropertyDescriptor(obj, pathArr[i]) || Object.getOwnPropertyDescriptor(Object.prototype, pathArr[i]);
if (descriptor && !descriptor.enumerable) {
return;
}

obj = obj[pathArr[i]];

if (obj === undefined) {
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ test('get', t => {
t.is(m.get({foo: {bar: {baz: null}}}, 'foo.bar.baz'), null);
t.is(m.get({foo: {bar: 'a'}}, 'foo.fake.fake2'), undefined);

const f2 = {};
Object.defineProperty(f2, 'foo', {value: 'bar', enumerable: false});
t.is(m.get(f2, 'foo'), undefined);
t.is(m.get({}, 'hasOwnProperty'), undefined);

function fn() {}
fn.foo = {bar: 1};
t.is(m.get(fn), fn);
Expand Down

0 comments on commit 2c301fa

Please sign in to comment.