mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
add pick + exclude object util
This commit is contained in:
parent
8d6b1aa791
commit
e78c97f926
1 changed files with 18 additions and 0 deletions
18
utils/common.ts
Normal file
18
utils/common.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
export function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K> {
|
||||||
|
const filtered = {} as Pick<T, K>
|
||||||
|
keys.forEach((key) => {
|
||||||
|
filtered[key] = obj[key]
|
||||||
|
})
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
export function exclude<T, K extends keyof T>(
|
||||||
|
obj: T,
|
||||||
|
...keys: K[]
|
||||||
|
): Omit<T, K> {
|
||||||
|
const filtered = { ...obj }
|
||||||
|
keys.forEach((key) => {
|
||||||
|
delete filtered[key]
|
||||||
|
})
|
||||||
|
return filtered
|
||||||
|
}
|
Loading…
Reference in a new issue