From e78c97f926fe1791aca3e45ac389a856548dee5f Mon Sep 17 00:00:00 2001 From: axolotle Date: Mon, 28 Aug 2023 19:12:46 +0200 Subject: [PATCH] add pick + exclude object util --- utils/common.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 utils/common.ts diff --git a/utils/common.ts b/utils/common.ts new file mode 100644 index 0000000..eb12cc4 --- /dev/null +++ b/utils/common.ts @@ -0,0 +1,18 @@ +export function pick(obj: T, ...keys: K[]): Pick { + const filtered = {} as Pick + keys.forEach((key) => { + filtered[key] = obj[key] + }) + return filtered +} + +export function exclude( + obj: T, + ...keys: K[] +): Omit { + const filtered = { ...obj } + keys.forEach((key) => { + delete filtered[key] + }) + return filtered +}