Skip to content

Commit

Permalink
chore: redundant comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pomykaczi committed Mar 21, 2024
1 parent 3b42348 commit f3573f3
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/utils/get.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@

export function get(obj: Record<string, any> | 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;
}

0 comments on commit f3573f3

Please sign in to comment.