Skip to content

Commit 25623ae

Browse files
committed
docs: Add docs in forEach & findKey as JSDoc
1 parent 3123121 commit 25623ae

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/compat/array/forEach.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function forEach<T>(
104104
* Iterates over each element of the object invoking the provided callback function for each property.
105105
*
106106
* @template T - The type of object.
107-
* @param {T} object - The object to iterate over
107+
* @param {T} object - The object to iterate over.
108108
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} [callback] - The function invoked for each property.
109109
* The callback function receives three arguments:
110110
* - 'value': The current property being processed in the object.
@@ -123,6 +123,24 @@ export function forEach<T extends object | null | undefined>(
123123
callback?: (value: T[keyof T], key: keyof T, object: T) => unknown
124124
): T;
125125

126+
/**
127+
* Iterates over each element of the object invoking the provided callback function for each property.
128+
*
129+
* @template T - The type of object.
130+
* @param {T} object - The object to iterate over.
131+
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} [callback] - The function invoked for each property.
132+
* The callback function receives three arguments:
133+
* - 'value': The current property being processed in the object.
134+
* - 'key': The key of the current property being processed in the object.
135+
* - 'object': The object 'forEach' was called upon.
136+
* @returns {T} Returns the original object.
137+
*
138+
* @example
139+
* forEach({'a': 1, 'b': 2 }, (value, key, object) => console.log(value, key));
140+
* // Output:
141+
* // 1 'a'
142+
* // 2 'b'
143+
*/
126144
export function forEach<T>(
127145
collection: ArrayLike<T> | Record<any, any> | string | null | undefined,
128146
callback: (item: any, index: any, arr: any) => unknown = identity

src/object/findKey.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Finds the key of the first element in the object that satisfies the provided testing function.
33
*
4-
* @param obj - The object to search.
5-
* @param predicate - The function to execute on each value in the object. It takes three arguments:
4+
* @param {T} obj - The object to search.
5+
* @param {(value: T[keyof T], key: keyof T, obj: T) => boolean} predicate - The function to execute on each value in the object. It takes three arguments:
66
* - value: The current value being processed in the object.
77
* - key: The key of the current value being processed in the object.
88
* - obj: The object that findKey was called upon.
9-
* @returns The key of the first element in the object that passes the test, or undefined if no element passes.
9+
* @returns {keyof T | undefined} The key of the first element in the object that passes the test, or undefined if no element passes.
1010
*
1111
* @example
1212
* const users = {

0 commit comments

Comments
 (0)