source: node_modules/es-toolkit/dist/compat/array/find.d.mts

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

Added visualizations

  • Property mode set to 100644
File size: 2.7 KB
Line 
1import { ListIterateeCustom } from '../_internal/ListIterateeCustom.mjs';
2import { ListIteratorTypeGuard } from '../_internal/ListIteratorTypeGuard.mjs';
3import { ObjectIterateeCustom } from '../_internal/ObjectIteratee.mjs';
4import { ObjectIteratorTypeGuard } from '../_internal/ObjectIterator.mjs';
5
6/**
7 * Finds the first element in an array-like object that matches a type guard predicate.
8 *
9 * @param collection - The array-like object to search
10 * @param predicate - The type guard function to test each element
11 * @param fromIndex - The index to start searching from
12 * @returns The first element that matches the type guard, or undefined if none found
13 *
14 * @example
15 * find([1, '2', 3], (x): x is number => typeof x === 'number')
16 * // => 1
17 */
18declare function find<T, U extends T>(collection: ArrayLike<T> | null | undefined, predicate: ListIteratorTypeGuard<T, U>, fromIndex?: number): U | undefined;
19/**
20 * Finds the first element in an array-like object that matches a predicate.
21 *
22 * @param collection - The array-like object to search
23 * @param predicate - The function or shorthand to test each element
24 * @param fromIndex - The index to start searching from
25 * @returns The first matching element, or undefined if none found
26 *
27 * @example
28 * find([1, 2, 3], x => x > 2)
29 * // => 3
30 *
31 * find([{ a: 1 }, { a: 2 }], { a: 2 })
32 * // => { a: 2 }
33 */
34declare function find<T>(collection: ArrayLike<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined;
35/**
36 * Finds the first value in an object that matches a type guard predicate.
37 *
38 * @param collection - The object to search
39 * @param predicate - The type guard function to test each value
40 * @param fromIndex - The index to start searching from
41 * @returns The first value that matches the type guard, or undefined if none found
42 *
43 * @example
44 * find({ a: 1, b: '2', c: 3 }, (x): x is number => typeof x === 'number')
45 * // => 1
46 */
47declare function find<T extends object, U extends T[keyof T]>(collection: T | null | undefined, predicate: ObjectIteratorTypeGuard<T, U>, fromIndex?: number): U | undefined;
48/**
49 * Finds the first value in an object that matches a predicate.
50 *
51 * @param collection - The object to search
52 * @param predicate - The function or shorthand to test each value
53 * @param fromIndex - The index to start searching from
54 * @returns The first matching value, or undefined if none found
55 *
56 * @example
57 * find({ a: 1, b: 2 }, x => x > 1)
58 * // => 2
59 *
60 * find({ a: { x: 1 }, b: { x: 2 } }, { x: 2 })
61 * // => { x: 2 }
62 */
63declare function find<T extends object>(collection: T | null | undefined, predicate?: ObjectIterateeCustom<T, boolean>, fromIndex?: number): T[keyof T] | undefined;
64
65export { find };
Note: See TracBrowser for help on using the repository browser.