invert-kv

  • Version 4.2.0
  • Published
  • 3.33 kB
  • No dependencies
  • MIT license

Install

npm i invert-kv
yarn add invert-kv
pnpm add invert-kv

Overview

Invert the key/value of an object. Example: `{foo: 'bar'}` → `{bar: 'foo'}`

Index

Functions

function invertKeyValue

invertKeyValue: <T extends Record<PropertyKey, PropertyKey>>(
object: T
) => {
[P in keyof T as T[P]]: keyof T extends number
? string | Exclude<keyof T, number>
: P;
};
  • Invert the key/value of an object.

    Example 1

    import invertKeyValue from 'invert-kv';
    invertKeyValue({foo: 'bar', '🦄': '🌈'});
    //=> {bar: 'foo', '🌈': '🦄'}

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (3)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/invert-kv.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/invert-kv)
  • HTML
    <a href="https://www.jsdocs.io/package/invert-kv"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>