UNPKG

hd-utils

Version:

A handy utils for modern JS developers

22 lines (21 loc) 911 B
import { KeysArr, PredicateFunc } from '../types'; /** * @description "It returns a new object that contains only the enumerable properties of the original object that * match the predicate." * * The predicate can be either an array of keys or a function that takes the key, value, and object as * arguments * @param object - The object to copy enumerable properties from. * @param predicate - A function that returns true if the key should be included in the result. * @example includeKeys({ foo: true, bar: false }, (key, value) => value === true) => {foo: true} * @example includeKeys({ foo: true, bar: false }, ["foo"]) => {foo:true} * @returns A new object with the same enumerable properties as the original object, but with the * values filtered by the predicate. */ export default function includeKeys<T extends object>(object: T, predicate: KeysArr | PredicateFunc<T>): {};