|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [a762898] | 1 | /**
|
|---|
| 2 | * Creates a new object composed of the properties that satisfy the predicate function.
|
|---|
| 3 | *
|
|---|
| 4 | * This function takes an object and a predicate function, and returns a new object that
|
|---|
| 5 | * includes only the properties for which the predicate function returns true.
|
|---|
| 6 | *
|
|---|
| 7 | * @template T - The type of object.
|
|---|
| 8 | * @param {T} obj - The object to pick properties from.
|
|---|
| 9 | * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
|
|---|
| 10 | * whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|---|
| 11 | * if the property should be picked, and `false` otherwise.
|
|---|
| 12 | * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * const obj = { a: 1, b: 'pick', c: 3 };
|
|---|
| 16 | * const shouldPick = (value) => typeof value === 'string';
|
|---|
| 17 | * const result = pickBy(obj, shouldPick);
|
|---|
| 18 | * // result will be { b: 'pick' }
|
|---|
| 19 | */
|
|---|
| 20 | declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
|---|
| 21 |
|
|---|
| 22 | export { pickBy };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.