UNPKG

es-next-tools

Version:

A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.

16 lines (15 loc) 630 B
/** * Inverts the keys and values of an object. * Currently, this function only supports PropertyKey type (string | number | symbol) * @param {Readonly<T>} object - The object to invert. * @returns A new object with the original object's values as keys and keys as values. * @example * const obj = { a: 1, b: 2, c: 3 }; * const inverted = invert(obj); * // { '1': 'a', '2': 'b', '3': 'c' } */ export type Invertible = Record<PropertyKey, PropertyKey>; export type Inverted<T extends Invertible> = { [K in keyof T as T[K]]: K; }; export declare function invert<T extends Invertible>(object: Readonly<T>): Inverted<T>;