Invert the key/value of an object. Example: {foo: 'bar'} → {bar: 'foo'}
by sindresorhusJavaScript
Last 12 weeks · 0 commits
4 of 6 standards met
Making use of 'keyof' and 'as' keywords, it's possible to make typization much stronger, even allowing to invert the object again and again without losing any types. Before: Calling non-existent keys should have failed, but works ok due to the lack of typization. After: Wow, how is that possible. The type checking has... unfolded in all its power. The solution is based on this StackOverflow thread: https://stackoverflow.com/a/56416192/11474669
Repository: sindresorhus/invert-kv. Description: Invert the key/value of an object. Example: {foo: 'bar'} → {bar: 'foo'} Stars: 37, Forks: 6. Primary language: JavaScript. Languages: JavaScript (74.6%), TypeScript (25.4%). License: MIT. Latest release: v4.2.0 (4y ago). Open PRs: 0, open issues: 0. Last activity: 4y ago. Community health: 85%. Top contributors: sindresorhus, artginzburg, BendingBender, filipemerker, Richienb.