function pick (object: O, keys: K[]): Pick { const result: any = {} for (const key of keys) { if (Object.prototype.hasOwnProperty.call(object, key)) { result[key] = object[key] } } return result } function omit (object: O, keys: K[]): Exclude { const result: any = {} const keysSet = new Set(keys) as Set for (const [ key, value ] of Object.entries(object)) { if (keysSet.has(key)) continue result[key] = value } return result } function getKeys (object: O, keys: K[]): K[] { return (Object.keys(object) as K[]).filter(k => keys.includes(k)) } function sortObjectComparator (key: string, order: 'asc' | 'desc') { return (a: any, b: any) => { if (a[key] < b[key]) { return order === 'asc' ? -1 : 1 } if (a[key] > b[key]) { return order === 'asc' ? 1 : -1 } return 0 } } function shallowCopy (o: T): T { return Object.assign(Object.create(Object.getPrototypeOf(o)), o) } export { pick, omit, getKeys, shallowCopy, sortObjectComparator }