pax_global_header00006660000000000000000000000064136575475210014531gustar00rootroot0000000000000052 comment=11d03f0a4a9ec8ee23e90211340ec60e830c12b8 invert-kv-3.0.1/000077500000000000000000000000001365754752100134575ustar00rootroot00000000000000invert-kv-3.0.1/.editorconfig000066400000000000000000000002571365754752100161400ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 invert-kv-3.0.1/.gitattributes000066400000000000000000000000231365754752100163450ustar00rootroot00000000000000* text=auto eol=lf invert-kv-3.0.1/.github/000077500000000000000000000000001365754752100150175ustar00rootroot00000000000000invert-kv-3.0.1/.github/funding.yml000066400000000000000000000001631365754752100171740ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/invert-kv custom: https://sindresorhus.com/donate invert-kv-3.0.1/.github/security.md000066400000000000000000000002631365754752100172110ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. invert-kv-3.0.1/.gitignore000066400000000000000000000000271365754752100154460ustar00rootroot00000000000000node_modules yarn.lock invert-kv-3.0.1/.npmrc000066400000000000000000000000231365754752100145720ustar00rootroot00000000000000package-lock=false invert-kv-3.0.1/.travis.yml000066400000000000000000000000761365754752100155730ustar00rootroot00000000000000language: node_js node_js: - '14' - '12' - '10' - '8' invert-kv-3.0.1/index.d.ts000066400000000000000000000011731365754752100153620ustar00rootroot00000000000000// TODO: Extend this to symbol when TS allows symbols in index signatures: // https://github.com/Microsoft/TypeScript/issues/1863 /** Invert the key/value of an object. Example: `{foo: 'bar'}` → `{bar: 'foo'}`. @example ``` import invertKeyValue = require('invert-kv'); invertKeyValue({foo: 'bar', '🦄': '🌈'}); //=> {bar: 'foo', '🌈': '🦄'} ``` */ declare function invertKeyValue< KeyType extends string | number, ValueType extends string | number | symbol >( object: {[key in KeyType]: ValueType} ): {[key in ValueType]: KeyType extends number ? Exclude | string : KeyType}; export = invertKeyValue; invert-kv-3.0.1/index.js000066400000000000000000000006101365754752100151210ustar00rootroot00000000000000'use strict'; module.exports = object => { if (typeof object !== 'object' || object === null) { throw new TypeError('Expected an object'); } const result = {}; for (const [key, value] of Object.entries(object)) { result[value] = key; } for (const symbol of Object.getOwnPropertySymbols(object)) { const value = object[symbol]; result[value] = symbol; } return result; }; invert-kv-3.0.1/index.test-d.ts000066400000000000000000000004261365754752100163370ustar00rootroot00000000000000import {expectType} from 'tsd'; import invertKeyValue = require('.'); expectType<{[key: string]: string}>(invertKeyValue({foo: 'bar', '🦄': '🌈'})); expectType<{[key: number]: string}>(invertKeyValue({foo: 1})); expectType<{[key: number]: string}>(invertKeyValue({1: 1})); invert-kv-3.0.1/license000066400000000000000000000021351365754752100150250ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. invert-kv-3.0.1/package.json000066400000000000000000000012471365754752100157510ustar00rootroot00000000000000{ "name": "invert-kv", "version": "3.0.1", "description": "Invert the key/value of an object. Example: `{foo: 'bar'}` → `{bar: 'foo'}`", "license": "MIT", "repository": "sindresorhus/invert-kv", "funding": "https://github.com/sindresorhus/invert-kv?sponsor=1", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "object", "key", "value", "invert", "keys", "values" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } invert-kv-3.0.1/readme.md000066400000000000000000000015211365754752100152350ustar00rootroot00000000000000# invert-kv [![Build Status](https://travis-ci.com/sindresorhus/invert-kv.svg?branch=master)](https://travis-ci.com/sindresorhus/invert-kv) > Invert the key/value of an object. Example: `{foo: 'bar'}` → `{bar: 'foo'}` ## Install ``` $ npm install invert-kv ``` ## Usage ```js const invertKeyValue = require('invert-kv'); invertKeyValue({foo: 'bar', '🦄': '🌈'}); //=> {bar: 'foo', '🌈': '🦄'} ``` ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
invert-kv-3.0.1/test.js000066400000000000000000000013161365754752100147750ustar00rootroot00000000000000import test from 'ava'; import invertKeyValue from '.'; test('throws an error if wrong type is given', t => { t.throws( () => { invertKeyValue(null); }, { instanceOf: TypeError, message: 'Expected an object' } ); }); test('inverts string/number properties', t => { t.deepEqual( invertKeyValue({foo: 'bar', unicorn: 'rainbow', 1: 'one'}), {bar: 'foo', rainbow: 'unicorn', one: '1'} ); }); test('inverts symbol properties', t => { const symbol = Symbol('fixture'); t.deepEqual( invertKeyValue({foo: symbol, unicorn: 'rainbow'}), {[symbol]: 'foo', rainbow: 'unicorn'} ); t.deepEqual( invertKeyValue({[symbol]: 'foo', rainbow: 'unicorn'}), {foo: symbol, unicorn: 'rainbow'} ); });