UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

47 lines (46 loc) 1.47 kB
import { ArrayIteratee, RecordIteratee, Tuple } from "./types"; /** * Creates an array of values by running each element in `collection` thru * `iteratee`. The iteratee is invoked with three arguments: * (value, index|key, collection). * * Many lodash methods are guarded to work as iteratee for methods like * `every`, `filter`, `map`, `mapValues`, `reject`, and `some`. * * The guarded methods are: * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, * `template`, `trim`, `trimEnd`, `trimStart`, and `words` * * @since 5.0.0 * @category Collection * @example * * ```js * 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) * * var users = [ * { 'user': 'barney' }, * { 'user': 'fred' } * ]; * * map(users, 'user'); * // => ['barney', 'fred'] * * ``` * */ export declare function map<T extends any[] | []>(collection: T): Tuple<T>; export declare function map<T, R = any>(collection: ArrayLike<T>, iteratee?: ArrayIteratee<T, R>): R[]; export declare function map<T, R = any>(collection: Record<string, T>, iteratee?: RecordIteratee<T, R>): R[]; export declare function map(collection: any, iteratee?: any): []; export default map;