-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69c735b
commit a9ed390
Showing
3 changed files
with
10 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
export function getValue(obj, path) { | ||
import type { Item } from '#types/Item' | ||
|
||
function getNestedValue(obj: Object, path: string) { | ||
Check warning on line 3 in src/Utils/GetValue.ts GitHub Actions / Lint
|
||
re | ||
} | ||
|
||
export function getValue(obj: Item | undefined, path: string): Item | string | undefined { | ||
if (!obj || typeof path !== 'string') return undefined | ||
|
||
const pathArray = path.split('.') // Use a different variable for the split path | ||
for (let i = 0, len = pathArray.length; i < len; i++) { | ||
if (!obj) return undefined // Check if obj is falsy at each step | ||
// eslint-disable-next-line security/detect-object-injection | ||
obj = obj[pathArray[i]] // Dive one level deeper | ||
obj = obj[pathArray[i]] as Item // Dive one level deeper | ||
} | ||
return obj // Return the final value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters