Skip to content

Commit 2b79a8c

Browse files
derekrliangdanivek
authored andcommitted
fix: update native get (#94)
* fix: update native get `Object.hasOwnProperty` doesn't seem to work in all situations https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get has updated their implementation and this is just updating it to the new one that fixes this issue.
1 parent 57bb656 commit 2b79a8c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/helpers.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const set = require('lodash.set');
1313
const LRU = require('./lru-cache');
1414

1515
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
16-
const get = (obj, path, defaultValue) =>
17-
String.prototype.split
16+
const get = (obj, path, defaultValue) => {
17+
const result = String.prototype.split
1818
.call(path, /[,[\].]+?/)
1919
.filter(Boolean)
20-
.reduce((a, c) => (Object.hasOwnProperty.call(a, c) ? a[c] : defaultValue), obj);
20+
.reduce((res, key) => (res !== null && res !== undefined ? res[key] : res), obj);
21+
return result === undefined || result === obj ? defaultValue : result;
22+
};
2123

2224
module.exports = {
2325
get,

0 commit comments

Comments
 (0)