Skip to content

Commit

Permalink
docs: Add docs in forEach & findKey as JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Nov 10, 2024
1 parent 3123121 commit 25623ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/compat/array/forEach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function forEach<T>(
* Iterates over each element of the object invoking the provided callback function for each property.
*
* @template T - The type of object.
* @param {T} object - The object to iterate over
* @param {T} object - The object to iterate over.
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} [callback] - The function invoked for each property.
* The callback function receives three arguments:
* - 'value': The current property being processed in the object.
Expand All @@ -123,6 +123,24 @@ export function forEach<T extends object | null | undefined>(
callback?: (value: T[keyof T], key: keyof T, object: T) => unknown
): T;

/**
* Iterates over each element of the object invoking the provided callback function for each property.
*
* @template T - The type of object.
* @param {T} object - The object to iterate over.
* @param {(value: T[keyof T], key: keyof T, object: T) => unknown} [callback] - The function invoked for each property.
* The callback function receives three arguments:
* - 'value': The current property being processed in the object.
* - 'key': The key of the current property being processed in the object.
* - 'object': The object 'forEach' was called upon.
* @returns {T} Returns the original object.
*
* @example
* forEach({'a': 1, 'b': 2 }, (value, key, object) => console.log(value, key));
* // Output:
* // 1 'a'
* // 2 'b'
*/
export function forEach<T>(
collection: ArrayLike<T> | Record<any, any> | string | null | undefined,
callback: (item: any, index: any, arr: any) => unknown = identity
Expand Down
6 changes: 3 additions & 3 deletions src/object/findKey.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Finds the key of the first element in the object that satisfies the provided testing function.
*
* @param obj - The object to search.
* @param predicate - The function to execute on each value in the object. It takes three arguments:
* @param {T} obj - The object to search.
* @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:
* - value: The current value being processed in the object.
* - key: The key of the current value being processed in the object.
* - obj: The object that findKey was called upon.
* @returns The key of the first element in the object that passes the test, or undefined if no element passes.
* @returns {keyof T | undefined} The key of the first element in the object that passes the test, or undefined if no element passes.
*
* @example
* const users = {
Expand Down

0 comments on commit 25623ae

Please sign in to comment.