mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-05-12 02:56:13 +08:00
feat: omit function
This commit is contained in:
22
webui/src/utils/omit.test.ts
Normal file
22
webui/src/utils/omit.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { omit } from './omit';
|
||||
|
||||
it('test omit', () => {
|
||||
const obj = {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: 4,
|
||||
};
|
||||
|
||||
expect(omit(obj, ['a'])).toStrictEqual({
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: 4,
|
||||
});
|
||||
|
||||
expect(omit(obj, ['b', 'c'])).toStrictEqual({
|
||||
a: 1,
|
||||
d: 4,
|
||||
});
|
||||
});
|
||||
12
webui/src/utils/omit.ts
Normal file
12
webui/src/utils/omit.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function omit<T extends { [k: string]: any }>(
|
||||
obj: T,
|
||||
omitKeys: Array<keyof T>
|
||||
) {
|
||||
return Object.keys(obj).reduce((acc, key) => {
|
||||
if (omitKeys.includes(key)) {
|
||||
return acc;
|
||||
} else {
|
||||
return { ...acc, [key]: obj[key] };
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
Reference in New Issue
Block a user