source: node_modules/es-toolkit/dist/compat/object/pickBy.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 905 bytes
Line 
1import { keysIn } from './keysIn.mjs';
2import { range } from '../../math/range.mjs';
3import { getSymbolsIn } from '../_internal/getSymbolsIn.mjs';
4import { identity } from '../function/identity.mjs';
5import { isArrayLike } from '../predicate/isArrayLike.mjs';
6import { isSymbol } from '../predicate/isSymbol.mjs';
7import { iteratee } from '../util/iteratee.mjs';
8
9function pickBy(obj, shouldPick) {
10 if (obj == null) {
11 return {};
12 }
13 const predicate = iteratee(shouldPick ?? identity);
14 const result = {};
15 const keys = isArrayLike(obj) ? range(0, obj.length) : [...keysIn(obj), ...getSymbolsIn(obj)];
16 for (let i = 0; i < keys.length; i++) {
17 const key = (isSymbol(keys[i]) ? keys[i] : keys[i].toString());
18 const value = obj[key];
19 if (predicate(value, key, obj)) {
20 result[key] = value;
21 }
22 }
23 return result;
24}
25
26export { pickBy };
Note: See TracBrowser for help on using the repository browser.