Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
The invert-kv npm package is a simple utility that allows you to invert the keys and values of an object. This means that 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. It is particularly useful when you need to reverse the mapping of an object for easier access based on values rather than keys.
Inverting key-value pairs
This feature allows you to swap the keys and values of an object. The code sample demonstrates how to use invert-kv to invert the keys and values of a simple object.
{ const invertKv = require('invert-kv'); const original = { a: '1', b: '2' }; const inverted = invertKv(original); console.log(inverted); // Output: { '1': 'a', '2': 'b' } }
Lodash's invert function is part of the larger lodash library, which offers a wide range of utility functions for JavaScript. Lodash.invert performs a similar function to invert-kv by creating an object composed of the inverted keys and values of the original object. The main difference is that lodash.invert is part of a larger library, which might not be ideal if you are looking for a package with a singular focus like invert-kv.
Reverse-object is another npm package that provides functionality to reverse the keys and values of an object. It is similar to invert-kv but might have different handling for specific edge cases or performance optimizations. It's another alternative for those looking for a utility focused solely on this task.
Invert the key/value of an object. Example:
{foo: 'bar'}
→{bar: 'foo'}
$ npm install invert-kv
import invertKeyValue from 'invert-kv';
invertKeyValue({foo: 'bar', '🦄': '🌈'});
//=> {bar: 'foo', '🌈': '🦄'}
FAQs
Invert the key/value of an object. Example: `{foo: 'bar'}` → `{bar: 'foo'}`
The npm package invert-kv receives a total of 3,120,381 weekly downloads. As such, invert-kv popularity was classified as popular.
We found that invert-kv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.