explaingit

sindresorhus/invert-kv

Analysis updated 2026-07-17 · repo last pushed 2022-02-26

37JavaScriptAudience · developerComplexity · 1/5DormantSetup · easy

TLDR

A tiny JavaScript utility that swaps an object's keys and values, turning a lookup table pointing one way into one pointing the other way.

Mindmap

mindmap
  root((repo))
    What it does
      Swaps keys and values
      Returns new object
      Works with strings
    Tech stack
      JavaScript
      npm package
    Use cases
      Reverse lookup tables
      Country code mapping
      Search features
    Audience
      JS developers
      Data importers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Flip a country-code-to-name lookup table into a name-to-code table without writing swap logic yourself

USE CASE 2

Reverse a settings or config object so values become keys for fast reverse lookups

USE CASE 3

Build a search feature that needs to look up an original key from a value someone typed in

What is it built with?

JavaScriptNode.js

How does it compare?

sindresorhus/invert-kvavacocloud/avaco-railwaymatem6/p2jb-y2jb-porting
Stars373737
LanguageJavaScriptJavaScriptJavaScript
Last pushed2022-02-26
MaintenanceDormant
Setup difficultyeasymoderatehard
Complexity1/53/55/5
Audiencedeveloperops devopsresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

In plain English

Invert-kv is a small JavaScript utility that flips an object's keys and values. If you have an object where "foo" points to "bar," running it through this package gives you back an object where "bar" points to "foo" instead. The concept is straightforward: you pass in an object, and the package returns a new object with every key-value pair swapped. The README's example shows that if you give it an object mapping a unicorn emoji to a rainbow emoji, it hands back one mapping the rainbow to the unicorn. It works with strings, which is what JavaScript objects use as keys. This kind of tool comes in handy when you have a lookup table pointing in one direction and need it pointing the other way. For example, if you have a mapping of country codes to full country names (like "US" to "United States"), inverting it gives you a mapping from full names back to codes. A developer building a search feature, a data importer, or a settings panel might reach for something like this rather than writing the swap logic themselves. The package is installed through npm, which is the standard package manager for JavaScript projects. You bring it into your code with a single import statement and call it as a function. The README doesn't go into much detail beyond the basic usage example. There's no discussion of edge cases, performance, or what happens if two keys share the same value. It's a tiny, single-purpose helper from a well-known open source maintainer, and the stars suggest a modest but real user base that finds it useful enough to keep around.

Copy-paste prompts

Prompt 1
Show me how to use the invert-kv npm package to reverse a JavaScript object mapping country codes to country names.
Prompt 2
Write a small Node.js script that imports invert-kv and inverts a settings object, then logs the result.
Prompt 3
What happens with invert-kv if two keys in my object share the same value, which one wins after inverting?

Frequently asked questions

What is invert-kv?

A tiny JavaScript utility that swaps an object's keys and values, turning a lookup table pointing one way into one pointing the other way.

What language is invert-kv written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js.

Is invert-kv actively maintained?

Dormant — no commits in 2+ years (last push 2022-02-26).

How hard is invert-kv to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is invert-kv for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.