| 1 | import { ArrayIterator } from '../_internal/ArrayIterator.js';
|
|---|
| 2 | import { ObjectIterator } from '../_internal/ObjectIterator.js';
|
|---|
| 3 | import { StringIterator } from '../_internal/StringIterator.js';
|
|---|
| 4 |
|
|---|
| 5 | /**
|
|---|
| 6 | * Creates a new object by mapping each character in a string to a value.
|
|---|
| 7 | * @param obj - The string to iterate over
|
|---|
| 8 | * @param callback - The function invoked per character
|
|---|
| 9 | * @returns A new object with numeric keys and mapped values
|
|---|
| 10 | * @example
|
|---|
| 11 | * mapValues('abc', (char) => char.toUpperCase())
|
|---|
| 12 | * // => { '0': 'A', '1': 'B', '2': 'C' }
|
|---|
| 13 | */
|
|---|
| 14 | declare function mapValues<T>(obj: string | null | undefined, callback: StringIterator<T>): Record<number, T>;
|
|---|
| 15 | /**
|
|---|
| 16 | * Creates a new object by mapping each element in an array to a value.
|
|---|
| 17 | * @param array - The array to iterate over
|
|---|
| 18 | * @param callback - The function invoked per element
|
|---|
| 19 | * @returns A new object with numeric keys and mapped values
|
|---|
| 20 | * @example
|
|---|
| 21 | * mapValues([1, 2], (num) => num * 2)
|
|---|
| 22 | * // => { '0': 2, '1': 4 }
|
|---|
| 23 | */
|
|---|
| 24 | declare function mapValues<T, U>(array: T[], callback: ArrayIterator<T, U>): Record<number, U>;
|
|---|
| 25 | /**
|
|---|
| 26 | * Creates a new object by mapping each property value in an object to a new value.
|
|---|
| 27 | * @param obj - The object to iterate over
|
|---|
| 28 | * @param callback - The function invoked per property
|
|---|
| 29 | * @returns A new object with the same keys and mapped values
|
|---|
| 30 | * @example
|
|---|
| 31 | * mapValues({ a: 1, b: 2 }, (num) => num * 2)
|
|---|
| 32 | * // => { a: 2, b: 4 }
|
|---|
| 33 | */
|
|---|
| 34 | declare function mapValues<T extends object, U>(obj: T | null | undefined, callback: ObjectIterator<T, U>): {
|
|---|
| 35 | [P in keyof T]: U;
|
|---|
| 36 | };
|
|---|
| 37 | /**
|
|---|
| 38 | * Creates a new object by checking each value against a matcher object.
|
|---|
| 39 | * @param obj - The object to iterate over
|
|---|
| 40 | * @param iteratee - The object to match against
|
|---|
| 41 | * @returns A new object with boolean values indicating matches
|
|---|
| 42 | * @example
|
|---|
| 43 | * mapValues({ a: { x: 1 }, b: { x: 2 } }, { x: 2 })
|
|---|
| 44 | * // => { a: false, b: true }
|
|---|
| 45 | */
|
|---|
| 46 | declare function mapValues<T>(obj: Record<string, T> | Record<number, T> | null | undefined, iteratee: object): Record<string, boolean>;
|
|---|
| 47 | /**
|
|---|
| 48 | * Creates a new object by checking each value against a matcher object.
|
|---|
| 49 | * @param obj - The object to iterate over
|
|---|
| 50 | * @param iteratee - The object to match against
|
|---|
| 51 | * @returns A new object with boolean values indicating matches
|
|---|
| 52 | * @example
|
|---|
| 53 | * mapValues({ a: { x: 1 }, b: { x: 2 } }, { x: 2 })
|
|---|
| 54 | * // => { a: false, b: true }
|
|---|
| 55 | */
|
|---|
| 56 | declare function mapValues<T extends object>(obj: T | null | undefined, iteratee: object): {
|
|---|
| 57 | [P in keyof T]: boolean;
|
|---|
| 58 | };
|
|---|
| 59 | /**
|
|---|
| 60 | * Creates a new object by extracting a property from each value.
|
|---|
| 61 | * @param obj - The object to iterate over
|
|---|
| 62 | * @param iteratee - The property key to extract
|
|---|
| 63 | * @returns A new object with extracted property values
|
|---|
| 64 | * @example
|
|---|
| 65 | * mapValues({ a: { x: 1 }, b: { x: 2 } }, 'x')
|
|---|
| 66 | * // => { a: 1, b: 2 }
|
|---|
| 67 | */
|
|---|
| 68 | declare function mapValues<T, K extends keyof T>(obj: Record<string, T> | Record<number, T> | null | undefined, iteratee: K): Record<string, T[K]>;
|
|---|
| 69 | /**
|
|---|
| 70 | * Creates a new object by extracting values at a path from each value.
|
|---|
| 71 | * @param obj - The object to iterate over
|
|---|
| 72 | * @param iteratee - The path to extract
|
|---|
| 73 | * @returns A new object with extracted values
|
|---|
| 74 | * @example
|
|---|
| 75 | * mapValues({ a: { x: { y: 1 } }, b: { x: { y: 2 } } }, 'x.y')
|
|---|
| 76 | * // => { a: 1, b: 2 }
|
|---|
| 77 | */
|
|---|
| 78 | declare function mapValues<T>(obj: Record<string, T> | Record<number, T> | null | undefined, iteratee: string): Record<string, any>;
|
|---|
| 79 | /**
|
|---|
| 80 | * Creates a new object by extracting values at a path from each value.
|
|---|
| 81 | * @param obj - The object to iterate over
|
|---|
| 82 | * @param iteratee - The path to extract
|
|---|
| 83 | * @returns A new object with extracted values
|
|---|
| 84 | * @example
|
|---|
| 85 | * mapValues({ a: { x: { y: 1 } }, b: { x: { y: 2 } } }, 'x.y')
|
|---|
| 86 | * // => { a: 1, b: 2 }
|
|---|
| 87 | */
|
|---|
| 88 | declare function mapValues<T extends object>(obj: T | null | undefined, iteratee: string): {
|
|---|
| 89 | [P in keyof T]: any;
|
|---|
| 90 | };
|
|---|
| 91 | /**
|
|---|
| 92 | * Creates a new object from a string using identity function.
|
|---|
| 93 | * @param obj - The string to convert
|
|---|
| 94 | * @returns A new object with characters as values
|
|---|
| 95 | * @example
|
|---|
| 96 | * mapValues('abc')
|
|---|
| 97 | * // => { '0': 'a', '1': 'b', '2': 'c' }
|
|---|
| 98 | */
|
|---|
| 99 | declare function mapValues(obj: string | null | undefined): Record<number, string>;
|
|---|
| 100 | /**
|
|---|
| 101 | * Creates a new object using identity function.
|
|---|
| 102 | * @param obj - The object to clone
|
|---|
| 103 | * @returns A new object with the same values
|
|---|
| 104 | * @example
|
|---|
| 105 | * mapValues({ a: 1, b: 2 })
|
|---|
| 106 | * // => { a: 1, b: 2 }
|
|---|
| 107 | */
|
|---|
| 108 | declare function mapValues<T>(obj: Record<string, T> | Record<number, T> | null | undefined): Record<string, T>;
|
|---|
| 109 | /**
|
|---|
| 110 | * Creates a new object using identity function.
|
|---|
| 111 | * @param obj - The object to clone
|
|---|
| 112 | * @returns A new object with the same values
|
|---|
| 113 | * @example
|
|---|
| 114 | * mapValues({ a: 1, b: 2 })
|
|---|
| 115 | * // => { a: 1, b: 2 }
|
|---|
| 116 | */
|
|---|
| 117 | declare function mapValues<T extends object>(obj: T): T;
|
|---|
| 118 | /**
|
|---|
| 119 | * Creates a new object using identity function.
|
|---|
| 120 | * @param obj - The object to clone
|
|---|
| 121 | * @returns A new object with the same values, or empty object if input is null/undefined
|
|---|
| 122 | * @example
|
|---|
| 123 | * mapValues({ a: 1, b: 2 })
|
|---|
| 124 | * // => { a: 1, b: 2 }
|
|---|
| 125 | * mapValues(null)
|
|---|
| 126 | * // => {}
|
|---|
| 127 | */
|
|---|
| 128 | declare function mapValues<T extends object>(obj: T | null | undefined): Partial<T>;
|
|---|
| 129 |
|
|---|
| 130 | export { mapValues };
|
|---|