Skip to content

Commit

Permalink
Allow getting non-enumerable properties (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanis Benson authored Oct 7, 2020
1 parent 614e74a commit cbd7074
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ module.exports = {
}

for (let i = 0; i < pathArray.length; i++) {
if (!Object.prototype.propertyIsEnumerable.call(object, pathArray[i])) {
return value;
}

object = object[pathArray[i]];

if (object === undefined || object === null) {
Expand Down
9 changes: 7 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ test('get', t => {
value: 'bar',
enumerable: false
});
t.is(dotProp.get(fixture2, 'foo'), undefined);
t.is(dotProp.get({}, 'hasOwnProperty'), undefined);
t.is(dotProp.get(fixture2, 'foo'), 'bar');
t.is(dotProp.get({}, 'hasOwnProperty'), Object.prototype.hasOwnProperty);

function fn() {}
fn.foo = {bar: 1};
Expand All @@ -50,6 +50,11 @@ test('get', t => {
t.false(dotProp.get('foo', 'foo.bar', false));
t.false(dotProp.get([], 'foo.bar', false));
t.false(dotProp.get(undefined, 'foo.bar', false));

class F4Class {}
F4Class.prototype.foo = 1;
const f4 = new F4Class();
t.is(dotProp.get(f4, 'foo'), 1); // #46
});

test('set', t => {
Expand Down

0 comments on commit cbd7074

Please sign in to comment.