super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
90 lines (89 loc) • 2.56 kB
TypeScript
/**
* Creates an array of values by running each element in collection through iteratee.
*
* @param collection - The collection to iterate over
* @param iteratee - The function invoked per iteration
* @returns The new mapped array
*
* @example
* ```ts
* function square(n) {
* return n * n;
* }
*
* map([4, 8], square);
* // => [16, 64]
*
* map({ 'a': 4, 'b': 8 }, square);
* // => [16, 64] (iteration order is not guaranteed)
*
* const users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* // The `_.property` iteratee shorthand.
* map(users, 'user');
* // => ['barney', 'fred']
* ```
*/
export declare function map<T, R>(collection: T[], iteratee: ((value: T, index: number, collection: T[]) => R) | string): R[];
/**
* Creates a flattened array of values by running each element in collection
* through iteratee and flattening the mapped results. The iteratee is invoked
* with three arguments: (value, index|key, collection).
*
* @param collection - The collection to iterate over
* @param iteratee - The function invoked per iteration
* @returns The new flattened array
*
* @example
* ```ts
* function duplicate(n) {
* return [n, n];
* }
*
* flatMap([1, 2], duplicate);
* // => [1, 1, 2, 2]
* ```
*/
export declare function flatMap<T, R>(collection: T[], iteratee: ((value: T, index: number, collection: T[]) => R | R[]) | string): R[];
/**
* This method is like flatMap except that it recursively flattens the
* mapped results.
*
* @param collection - The collection to iterate over
* @param iteratee - The function invoked per iteration
* @returns The new flattened array
*
* @example
* ```ts
* function duplicate(n) {
* return [[[n, n]]];
* }
*
* flatMapDeep([1, 2], duplicate);
* // => [1, 1, 2, 2]
* ```
*/
export declare function flatMapDeep<T, R>(collection: T[], iteratee: ((value: T, index: number, collection: T[]) => R | R[]) | string): R[];
/**
* This method is like flatMap except that it recursively flattens the
* mapped results up to depth times.
*
* @param collection - The collection to iterate over
* @param iteratee - The function invoked per iteration
* @param depth - The maximum recursion depth
* @returns The new flattened array
*
* @example
* ```ts
* function duplicate(n) {
* return [[[n, n]]];
* }
*
* flatMapDepth([1, 2], duplicate, 2);
* // => [[1, 1], [2, 2]]
* ```
*/
export declare function flatMapDepth<T, R>(collection: T[], iteratee: ((value: T, index: number, collection: T[]) => R | R[]) | string, depth?: number): R[];