Skip to content

Commit

Permalink
fix: get function
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhdaware committed Nov 19, 2023
1 parent 734f218 commit 4b68e60
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/blade/src/utils/lodashButBetter/get.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
function getIn(obj: Record<string, any>, path: string, defaultValue?: any): any {
function getIn(obj: Record<string, any>, path: string): any {
if (!path) {
return undefined;
}

const keys = path.split('.');
let result = obj;

for (const key of keys) {
result = result?.[key];
if (result === undefined) {
return defaultValue;
return undefined;
}
}

return result !== undefined ? result : defaultValue;
return result;
}

export default getIn;

0 comments on commit 4b68e60

Please sign in to comment.