From cada4ac4496fde9f885a89dc70f0b1b8ce8aa313 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Mon, 13 Mar 2023 20:22:21 -0700 Subject: [PATCH] fix(getPath): cannot use 'in' operator to search in undefined --- src/get-path.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/get-path.js b/src/get-path.js index 3097f60..a5d10c6 100644 --- a/src/get-path.js +++ b/src/get-path.js @@ -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; }