Skip to content

Commit

Permalink
fix(getPath): cannot use 'in' operator to search in undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhooks committed Mar 14, 2023
1 parent 3a60f96 commit cada4ac
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/get-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
*/
export default function getPath(object, path) {
const segments = path.split('.');

/** @type {any} */
let current = object;
/** @type {string|undefined} */
let segment;
while ((segment = segments.shift())) {
if (!(segment in object)) {
if (!current || !(segment in current)) {
return;
}

object = object[segment];
current = object[segment];
}

return object;
}

0 comments on commit cada4ac

Please sign in to comment.