UNPKG

es-next-tools

Version:

A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.

20 lines (19 loc) 541 B
export function pick(object, keysOrPredicate) { const result = {}; if (Array.isArray(keysOrPredicate)) { for (const key of keysOrPredicate) { if (key in object) { result[key] = object[key]; } } } else if (typeof keysOrPredicate === 'function') { for (const key of Object.keys(object)) { const value = object[key]; if (keysOrPredicate(key, value)) { result[key] = value; } } } return result; }