mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 08:50:34 +01:00
feat(InputMenu): new component (#86)
This commit is contained in:
@@ -19,6 +19,27 @@ export function omit<Data extends object, Keys extends keyof Data>(data: Data, k
|
||||
return result as Omit<Data, Keys>
|
||||
}
|
||||
|
||||
export function get(object: Record<string, any>, path: (string | number)[] | string, defaultValue?: any): any {
|
||||
if (typeof path === 'string') {
|
||||
path = path.split('.').map((key) => {
|
||||
const numKey = Number(key)
|
||||
return Number.isNaN(numKey) ? key : numKey
|
||||
})
|
||||
}
|
||||
|
||||
let result: any = object
|
||||
|
||||
for (const key of path) {
|
||||
if (result === undefined || result === null) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
result = result[key]
|
||||
}
|
||||
|
||||
return result !== undefined ? result : defaultValue
|
||||
}
|
||||
|
||||
export function looseToNumber(val: any): any {
|
||||
const n = Number.parseFloat(val)
|
||||
return Number.isNaN(n) ? val : n
|
||||
|
||||
Reference in New Issue
Block a user