1 function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick<O, K> {
4 for (const key of keys) {
5 if (Object.prototype.hasOwnProperty.call(object, key)) {
6 result[key] = object[key]
13 function omit <O extends object, K extends keyof O> (object: O, keys: K[]): Exclude<O, K> {
14 const result: any = {}
15 const keysSet = new Set(keys) as Set<string>
17 for (const [ key, value ] of Object.entries(object)) {
18 if (keysSet.has(key)) continue
26 function getKeys <O extends object, K extends keyof O> (object: O, keys: K[]): K[] {
27 return (Object.keys(object) as K[]).filter(k => keys.includes(k))
30 function sortObjectComparator (key: string, order: 'asc' | 'desc') {
31 return (a: any, b: any) => {
32 if (a[key] < b[key]) {
33 return order === 'asc' ? -1 : 1
36 if (a[key] > b[key]) {
37 return order === 'asc' ? 1 : -1