| 1 | import { ArrayIterator } from '../_internal/ArrayIterator.mjs';
|
|---|
| 2 | import { ListIterator } from '../_internal/ListIterator.mjs';
|
|---|
| 3 | import { ObjectIterator } from '../_internal/ObjectIterator.mjs';
|
|---|
| 4 | import { TupleIterator } from '../_internal/TupleIterator.mjs';
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * Maps each element in a tuple to a new tuple of values using an iteratee.
|
|---|
| 8 | *
|
|---|
| 9 | * @param {T} collection - The tuple to iterate over
|
|---|
| 10 | * @param {TupleIterator<T, U>} iteratee - The function invoked per iteration
|
|---|
| 11 | * @returns {{ [K in keyof T]: U }} - Returns the new mapped tuple
|
|---|
| 12 | *
|
|---|
| 13 | * @example
|
|---|
| 14 | * // Using a transformation function on a tuple
|
|---|
| 15 | * const tuple = [1, 'hello', true] as const;
|
|---|
| 16 | * map(tuple, value => String(value)); // => ['1', 'hello', 'true']
|
|---|
| 17 | */
|
|---|
| 18 | declare function map<T extends readonly [unknown, ...unknown[]], U>(collection: T, iteratee: TupleIterator<T, U>): {
|
|---|
| 19 | [K in keyof T]: U;
|
|---|
| 20 | };
|
|---|
| 21 | /**
|
|---|
| 22 | * Maps each element in an array to a new array using an iteratee.
|
|---|
| 23 | *
|
|---|
| 24 | * @param {T[] | null | undefined} collection - The array to iterate over
|
|---|
| 25 | * @param {ArrayIterator<T, U>} iteratee - The function invoked per iteration
|
|---|
| 26 | * @returns {U[]} - Returns the new mapped array
|
|---|
| 27 | *
|
|---|
| 28 | * @example
|
|---|
| 29 | * // Using a transformation function on an array
|
|---|
| 30 | * const array = [1, 2, 3];
|
|---|
| 31 | * map(array, x => x * 2); // => [2, 4, 6]
|
|---|
| 32 | */
|
|---|
| 33 | declare function map<T, U>(collection: T[] | null | undefined, iteratee: ArrayIterator<T, U>): U[];
|
|---|
| 34 | /**
|
|---|
| 35 | * Maps each element in an array-like object to a new array using an iteratee.
|
|---|
| 36 | *
|
|---|
| 37 | * @param {ArrayLike<T> | null | undefined} collection - The array-like object to iterate over
|
|---|
| 38 | * @param {ListIterator<T, U>} iteratee - The function invoked per iteration
|
|---|
| 39 | * @returns {U[]} - Returns the new mapped array
|
|---|
| 40 | *
|
|---|
| 41 | * @example
|
|---|
| 42 | * // Using a transformation function on an array-like object
|
|---|
| 43 | * const arrayLike = { length: 2, 0: 'a', 1: 'b' };
|
|---|
| 44 | * map(arrayLike, x => x.toUpperCase()); // => ['A', 'B']
|
|---|
| 45 | */
|
|---|
| 46 | declare function map<T, U>(collection: ArrayLike<T> | null | undefined, iteratee: ListIterator<T, U>): U[];
|
|---|
| 47 | /**
|
|---|
| 48 | * Maps each value in an object to a new array.
|
|---|
| 49 | *
|
|---|
| 50 | * @param {Record<string, T> | Record<number, T> | null | undefined} collection - The object to iterate over
|
|---|
| 51 | * @returns {T[]} - Returns an array of the object's values
|
|---|
| 52 | *
|
|---|
| 53 | * @example
|
|---|
| 54 | * // Converting an object's values to an array
|
|---|
| 55 | * const obj = { a: 1, b: 2, c: 3 };
|
|---|
| 56 | * map(obj); // => [1, 2, 3]
|
|---|
| 57 | */
|
|---|
| 58 | declare function map<T>(collection: Record<string, T> | Record<number, T> | null | undefined): T[];
|
|---|
| 59 | /**
|
|---|
| 60 | * Maps each element in an object to a new array using an iteratee.
|
|---|
| 61 | *
|
|---|
| 62 | * @param {T | null | undefined} collection - The object to iterate over
|
|---|
| 63 | * @param {ObjectIterator<T, U>} iteratee - The function invoked per iteration
|
|---|
| 64 | * @returns {U[]} - Returns the new mapped array
|
|---|
| 65 | *
|
|---|
| 66 | * @example
|
|---|
| 67 | * // Using a transformation function on an object
|
|---|
| 68 | * const obj = { a: 1, b: 2 };
|
|---|
| 69 | * map(obj, (value, key) => `${key}:${value}`); // => ['a:1', 'b:2']
|
|---|
| 70 | */
|
|---|
| 71 | declare function map<T extends object, U>(collection: T | null | undefined, iteratee: ObjectIterator<T, U>): U[];
|
|---|
| 72 | /**
|
|---|
| 73 | * Maps each element in an object to a new array by plucking the specified property.
|
|---|
| 74 | *
|
|---|
| 75 | * @param {Record<string, T> | Record<number, T> | null | undefined} collection - The object to iterate over
|
|---|
| 76 | * @param {K} iteratee - The property to pluck from each element
|
|---|
| 77 | * @returns {Array<T[K]>} - Returns the new array of plucked values
|
|---|
| 78 | *
|
|---|
| 79 | * @example
|
|---|
| 80 | * // Plucking a property from each object
|
|---|
| 81 | * const users = [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }];
|
|---|
| 82 | * map(users, 'name'); // => ['John', 'Jane']
|
|---|
| 83 | */
|
|---|
| 84 | declare function map<T, K extends keyof T>(collection: Record<string, T> | Record<number, T> | null | undefined, iteratee: K): Array<T[K]>;
|
|---|
| 85 | /**
|
|---|
| 86 | * Maps each element in an object to a new array by plucking the specified string property.
|
|---|
| 87 | *
|
|---|
| 88 | * @param {Record<string, T> | Record<number, T> | null | undefined} collection - The object to iterate over
|
|---|
| 89 | * @param {string} [iteratee] - The string property to pluck from each element
|
|---|
| 90 | * @returns {any[]} - Returns the new array of plucked values
|
|---|
| 91 | *
|
|---|
| 92 | * @example
|
|---|
| 93 | * // Plucking a nested property
|
|---|
| 94 | * const users = [{ info: { name: 'John' } }, { info: { name: 'Jane' } }];
|
|---|
| 95 | * map(users, 'info.name'); // => ['John', 'Jane']
|
|---|
| 96 | */
|
|---|
| 97 | declare function map<T>(collection: Record<string, T> | Record<number, T> | null | undefined, iteratee?: string): any[];
|
|---|
| 98 | /**
|
|---|
| 99 | * Maps each element in an object to a new array by matching against a source object.
|
|---|
| 100 | *
|
|---|
| 101 | * @param {Record<string, T> | Record<number, T> | null | undefined} collection - The object to iterate over
|
|---|
| 102 | * @param {object} [iteratee] - The object to match against
|
|---|
| 103 | * @returns {boolean[]} - Returns an array of boolean values indicating matches
|
|---|
| 104 | *
|
|---|
| 105 | * @example
|
|---|
| 106 | * // Matching against a source object
|
|---|
| 107 | * const users = [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }];
|
|---|
| 108 | * map(users, { age: 30 }); // => [true, false]
|
|---|
| 109 | */
|
|---|
| 110 | declare function map<T>(collection: Record<string, T> | Record<number, T> | null | undefined, iteratee?: object): boolean[];
|
|---|
| 111 |
|
|---|
| 112 | export { map };
|
|---|