From f3573f3e3e17d0fa1a3487784bd33e4352c4a7b1 Mon Sep 17 00:00:00 2001 From: Ivan Pomykacz Date: Thu, 21 Mar 2024 08:45:36 +0200 Subject: [PATCH] chore: redundant comments --- src/utils/get.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/utils/get.ts b/src/utils/get.ts index e6474ee..5564348 100644 --- a/src/utils/get.ts +++ b/src/utils/get.ts @@ -1,14 +1,10 @@ export function get(obj: Record | undefined, path: string, defValue?: any): any { - // If path is not defined or it has false value - if (!path) return undefined; - // Check if path is string or array. Regex : ensure that we do not have '.' and brackets. // Regex explained: https://regexr.com/58j0k const pathArray = path.match(/([^[.\]])+/g); - // Find value const result = pathArray?.reduce((prevObj, key) => { return prevObj && prevObj[key]; }, obj); - // If found value is undefined return default value; otherwise return the value + return result === undefined ? defValue : result; }