UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

36 lines (35 loc) 2.16 kB
type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = { [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric; }; type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>; /** * Creates a new object with the same keys as the input object, but with values set to the result of * `mapCallback` for each property. This is the same as {@link mapObjectValues} except that this * preserves Promise values: it doesn't wrap them all in a single promise. * * @category Object * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function mapObjectValuesSync<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: Required<EntireInputGeneric>[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): InnerMappedValues<EntireInputGeneric, MappedValueGeneric>; /** * Creates a new object with the same keys as the input object, but with values set to the result of * `mapCallback` for each property. Automatically handles an async `mapCallback`. * * @category Object * @category Package : @augment-vir/common * @example * * ```ts * import {mapObjectValues} from '@augment-vir/common'; * * mapObjectValues({a: 1, b: 2}, (key, value) => { * return `key-${key} value-${value}`; * }); * // output is `{a: 'key-a value-1', b: 'key-b value-2'}` * ``` * * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function mapObjectValues<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: Required<EntireInputGeneric>[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): MappedValues<EntireInputGeneric, MappedValueGeneric>; export {};