source: node_modules/es-toolkit/dist/compat/array/forEach.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: 4.3 KB
Line 
1import { ArrayIterator } from '../_internal/ArrayIterator.mjs';
2import { ListIterator } from '../_internal/ListIterator.mjs';
3import { ObjectIterator } from '../_internal/ObjectIterator.mjs';
4import { StringIterator } from '../_internal/StringIterator.mjs';
5
6/**
7 * Iterates over elements of array and invokes iteratee for each element.
8 *
9 * @template T
10 * @param {T[]} collection - The array to iterate over.
11 * @param {ArrayIterator<T, any>} [iteratee] - The function invoked per iteration.
12 * @returns {T[]} Returns array.
13 *
14 * @example
15 * forEach([1, 2], value => console.log(value));
16 * // => Logs `1` then `2`.
17 */
18declare function forEach<T>(collection: T[], iteratee?: ArrayIterator<T, any>): T[];
19/**
20 * Iterates over characters of string and invokes iteratee for each character.
21 *
22 * @param {string} collection - The string to iterate over.
23 * @param {StringIterator<any>} [iteratee] - The function invoked per iteration.
24 * @returns {string} Returns string.
25 *
26 * @example
27 * forEach('abc', char => console.log(char));
28 * // => Logs 'a', 'b', then 'c'.
29 */
30declare function forEach(collection: string, iteratee?: StringIterator<any>): string;
31/**
32 * Iterates over elements of collection and invokes iteratee for each element.
33 *
34 * @template T
35 * @param {ArrayLike<T>} collection - The collection to iterate over.
36 * @param {ListIterator<T, any>} [iteratee] - The function invoked per iteration.
37 * @returns {ArrayLike<T>} Returns collection.
38 *
39 * @example
40 * forEach({ 0: 'a', 1: 'b', length: 2 }, value => console.log(value));
41 * // => Logs 'a' then 'b'.
42 */
43declare function forEach<T>(collection: ArrayLike<T>, iteratee?: ListIterator<T, any>): ArrayLike<T>;
44/**
45 * Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.
46 *
47 * @template T
48 * @param {T} collection - The object to iterate over.
49 * @param {ObjectIterator<T, any>} [iteratee] - The function invoked per iteration.
50 * @returns {T} Returns object.
51 *
52 * @example
53 * forEach({ a: 1, b: 2 }, (value, key) => console.log(key));
54 * // => Logs 'a' then 'b'.
55 */
56declare function forEach<T extends object>(collection: T, iteratee?: ObjectIterator<T, any>): T;
57/**
58 * Iterates over elements of array and invokes iteratee for each element.
59 *
60 * @template T, U
61 * @param {U & (T[] | null | undefined)} collection - The array to iterate over.
62 * @param {ArrayIterator<T, any>} [iteratee] - The function invoked per iteration.
63 * @returns {U} Returns the array.
64 *
65 * @example
66 * forEach([1, 2], value => console.log(value));
67 * // => Logs `1` then `2`.
68 */
69declare function forEach<T, U extends T[] | null | undefined>(collection: U & (T[] | null | undefined), iteratee?: ArrayIterator<T, any>): U;
70/**
71 * Iterates over characters of string and invokes iteratee for each character.
72 *
73 * @template T
74 * @param {T} collection - The string to iterate over.
75 * @param {StringIterator<any>} [iteratee] - The function invoked per iteration.
76 * @returns {T} Returns the string.
77 *
78 * @example
79 * forEach('abc', char => console.log(char));
80 * // => Logs 'a', 'b', then 'c'.
81 */
82declare function forEach<T extends string | null | undefined>(collection: T, iteratee?: StringIterator<any>): T;
83/**
84 * Iterates over elements of collection and invokes iteratee for each element.
85 *
86 * @template T, L
87 * @param {L & (ArrayLike<T> | null | undefined)} collection - The collection to iterate over.
88 * @param {ListIterator<T, any>} [iteratee] - The function invoked per iteration.
89 * @returns {L} Returns the collection.
90 *
91 * @example
92 * forEach({ 0: 'a', 1: 'b', length: 2 }, value => console.log(value));
93 * // => Logs 'a' then 'b'.
94 */
95declare function forEach<T, L extends ArrayLike<T> | null | undefined>(collection: L & (ArrayLike<T> | null | undefined), iteratee?: ListIterator<T, any>): L;
96/**
97 * Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.
98 *
99 * @template T
100 * @param {T | null | undefined} collection - The object to iterate over.
101 * @param {ObjectIterator<T, any>} [iteratee] - The function invoked per iteration.
102 * @returns {T | null | undefined} Returns the object.
103 *
104 * @example
105 * forEach({ a: 1, b: 2 }, (value, key) => console.log(key));
106 * // => Logs 'a' then 'b'.
107 */
108declare function forEach<T extends object>(collection: T | null | undefined, iteratee?: ObjectIterator<T, any>): T | null | undefined;
109
110export { forEach };
Note: See TracBrowser for help on using the repository browser.