source: node_modules/es-toolkit/dist/compat/array/find.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: 765 bytes
RevLine 
[a762898]1import { identity } from '../../function/identity.mjs';
2import { iteratee } from '../util/iteratee.mjs';
3
4function find(source, _doesMatch = identity, fromIndex = 0) {
5 if (!source) {
6 return undefined;
7 }
8 if (fromIndex < 0) {
9 fromIndex = Math.max(source.length + fromIndex, 0);
10 }
11 const doesMatch = iteratee(_doesMatch);
12 if (!Array.isArray(source)) {
13 const keys = Object.keys(source);
14 for (let i = fromIndex; i < keys.length; i++) {
15 const key = keys[i];
16 const value = source[key];
17 if (doesMatch(value, key, source)) {
18 return value;
19 }
20 }
21 return undefined;
22 }
23 return source.slice(fromIndex).find(doesMatch);
24}
25
26export { find };
Note: See TracBrowser for help on using the repository browser.