invert es-toolkit
Creates a new object with keys and values swapped.
Usage
invert(obj)
Use invert when you want to create a new object with keys and values swapped. The keys of the original object become the values of the new object, and the values of the original object become the keys of the new object. If there are duplicate values, the key that appears later will be used.
Can be used with various types of keys and values.
Useful when used with enums or constant objects.
Parameters
The object to swap keys and values. Both keys and values must be strings, numbers, or symbols.
Returns
A new object with the keys and values of the original object swapped.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.