sindresorhus/invert-kv — explained in plain English
Analysis updated 2026-07-17 · repo last pushed 2022-02-26
Flip a country-code-to-name lookup table into a name-to-code table without writing swap logic yourself
Reverse a settings or config object so values become keys for fast reverse lookups
Build a search feature that needs to look up an original key from a value someone typed in
| sindresorhus/invert-kv | avacocloud/avaco-railway | matem6/p2jb-y2jb-porting | |
|---|---|---|---|
| Stars | 37 | 37 | 37 |
| Language | JavaScript | JavaScript | JavaScript |
| Last pushed | 2022-02-26 | — | — |
| Maintenance | Dormant | — | — |
| Setup difficulty | easy | moderate | hard |
| Complexity | 1/5 | 3/5 | 5/5 |
| Audience | developer | ops devops | researcher |
Figures from each repo's GitHub metadata at analysis time.
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.
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.
Mainly JavaScript. The stack also includes JavaScript, Node.js.
Dormant — no commits in 2+ years (last push 2022-02-26).
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.