UNPKG

typedash

Version:

modern, type-safe collection of utility functions

1 lines 2.09 kB
{"version":3,"file":"pick-DP5vsdsF.cjs","names":["filterObject","createObjectPredicate"],"sources":["../src/functions/pick/pick.ts"],"sourcesContent":["import type { KeysOfUnion, Many, Maybe } from '../../types';\nimport {\n createObjectPredicate,\n filterObject,\n type ObjectPredicate,\n} from '../_internal/filterObject';\n\n/**\n * Returns a new object with only the specified properties from the input object.\n * @param object The input object to pick properties from.\n * @param properties An array of property names to pick from the input object.\n * @returns A new object with only the specified properties from the input object.\n */\nexport function pick<\n T extends object,\n const K extends keyof T | KeysOfUnion<T>,\n>(object: Maybe<T>, properties: Many<K>): Pick<T, K>;\n/**\n * Returns a new object with only the properties that satisfy the predicate function from the input object.\n * @param object The input object to pick properties from.\n * @param predicate A function that takes a property value and its key and returns a boolean indicating whether to pick the property or not.\n * @returns A new object with only the properties that satisfy the predicate function from the input object.\n */\nexport function pick<T extends object>(\n object: Maybe<T>,\n predicate: ObjectPredicate<T>\n): Partial<T>;\n/**\n * Implementation for all overloads.\n * @param object The input object to pick properties from.\n * @param propertiesOrPredicate Either an array of property names to pick from the input object or a function that takes a property value and its key and returns a boolean indicating whether to pick the property or not.\n * @returns A new object with only the specified properties from the input object.\n */\nexport function pick<\n T extends object,\n const K extends keyof T | KeysOfUnion<T>,\n>(object: Maybe<T>, propertiesOrPredicate: Many<K> | ObjectPredicate<T>) {\n return filterObject(object, createObjectPredicate(propertiesOrPredicate));\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAgB,KAGd,QAAkB,uBAAqD;AACvE,QAAOA,kCAAa,QAAQC,2CAAsB,sBAAsB,CAAC"}