{"_id":"@stdlib/object-inverse","_rev":"2-bcbbd4bca5b2078f683b2818ffc49db0","name":"@stdlib/object-inverse","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@stdlib/object-inverse","version":"0.1.0","keywords":["stdlib","stdutils","stdutil","utilities","utility","utils","util","inverse","invert","object","keys","values","bijection","mapping","hash","array"],"author":{"url":"https://github.com/stdlib-js/stdlib/graphs/contributors","name":"The Stdlib Authors"},"license":"Apache-2.0","_id":"@stdlib/object-inverse@0.1.0","maintainers":[{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"}],"contributors":[{"url":"https://github.com/stdlib-js/stdlib/graphs/contributors","name":"The Stdlib Authors"}],"homepage":"https://stdlib.io","bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"os":["aix","darwin","freebsd","linux","macos","openbsd","sunos","win32","windows"],"dist":{"shasum":"c6dcf3b209577660934a36aa5465dc014db1fb85","tarball":"https://registry.npmjs.org/@stdlib/object-inverse/-/object-inverse-0.1.0.tgz","fileCount":11,"integrity":"sha512-5nFmdadAg3aXWW/ahrnrSaeanbs/uHeRWClzfqanfyIpoqiBb19mBpOy07dKi6lJjTUJHQztjDxvHWkFh5FZtg==","signatures":[{"sig":"MEQCIEo1oq53NCKF7yBRUDCex/EtN3jDEQri5wXJMw9IouoWAiBhV3gtAL47qa5gEeR/Mo8ojCol/gcW9qZk/n1QB92JEw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33406},"main":"./lib","types":"./docs/types","engines":{"npm":">2.7.0","node":">=0.10.0"},"funding":{"url":"https://opencollective.com/stdlib","type":"opencollective"},"gitHead":"c300ff914062f53a0fcf2d195f694bbb90cc96a2","scripts":{},"_npmUser":{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},"repository":{"url":"git://github.com/stdlib-js/object-inverse.git","type":"git"},"_npmVersion":"10.8.2","description":"Invert an object, such that keys become values and values become keys.","directories":{"doc":"./docs","lib":"./lib","dist":"./dist"},"_nodeVersion":"20.20.0","dependencies":{"@stdlib/utils-keys":"^0.2.2","@stdlib/string-format":"^0.2.2","@stdlib/assert-is-array":"^0.2.2","@stdlib/assert-is-boolean":"^0.2.2","@stdlib/assert-is-object-like":"^0.2.2","@stdlib/assert-is-plain-object":"^0.2.2","@stdlib/error-tools-fmtprodmsg":"^0.2.2","@stdlib/assert-has-own-property":"^0.2.2"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/object-inverse_0.1.0_1769752845360_0.00795940277677043","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@stdlib/object-inverse","version":"0.1.1","description":"Invert an object, such that keys become values and values become keys.","license":"Apache-2.0","author":{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"},"contributors":[{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"}],"main":"./lib","directories":{"doc":"./docs","lib":"./lib","dist":"./dist"},"types":"./docs/types","scripts":{},"homepage":"https://stdlib.io","repository":{"type":"git","url":"git://github.com/stdlib-js/object-inverse.git"},"bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"dependencies":{"@stdlib/assert-has-own-property":"^0.2.3","@stdlib/assert-is-array":"^0.2.3","@stdlib/assert-is-boolean":"^0.2.3","@stdlib/assert-is-object-like":"^0.2.3","@stdlib/assert-is-plain-object":"^0.2.3","@stdlib/string-format":"^0.2.3","@stdlib/utils-keys":"^0.2.3","@stdlib/error-tools-fmtprodmsg":"^0.2.3"},"devDependencies":{},"engines":{"node":">=0.10.0","npm":">2.7.0"},"os":["aix","darwin","freebsd","linux","macos","openbsd","sunos","win32","windows"],"keywords":["stdlib","stdutils","stdutil","utilities","utility","utils","util","inverse","invert","object","keys","values","bijection","mapping","hash","array"],"funding":{"type":"opencollective","url":"https://opencollective.com/stdlib"},"_id":"@stdlib/object-inverse@0.1.1","gitHead":"65ac870bcc9363ee25cdde72514d9e0783b5395e","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-6hYJtS86ucnpIsZ1ElPbHOoZ/wRZiuwpfGK7tDxbi1G9WyZMn7vgydsb0/vYWdiNBTTTb3R6F17S1fPpUqxTjw==","shasum":"b829b0d6f39d196e8209f9837c8361abc52be6d7","tarball":"https://registry.npmjs.org/@stdlib/object-inverse/-/object-inverse-0.1.1.tgz","fileCount":11,"unpackedSize":33406,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCID3zWVzcUOiEXAjVJ57vzDM/p2AqnxVeu54nK/ktScEzAiEApaVkHJEPTyGAiWspwCAgevuASGqw66IkEc4SsFFnrxA="}]},"_npmUser":{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},"maintainers":[{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/object-inverse_0.1.1_1770502836689_0.27703551997490616"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-30T06:00:45.224Z","modified":"2026-02-07T22:20:36.995Z","0.1.0":"2026-01-30T06:00:45.513Z","0.1.1":"2026-02-07T22:20:36.818Z"},"bugs":{"url":"https://github.com/stdlib-js/stdlib/issues"},"author":{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"},"license":"Apache-2.0","homepage":"https://stdlib.io","keywords":["stdlib","stdutils","stdutil","utilities","utility","utils","util","inverse","invert","object","keys","values","bijection","mapping","hash","array"],"repository":{"type":"git","url":"git://github.com/stdlib-js/object-inverse.git"},"description":"Invert an object, such that keys become values and values become keys.","contributors":[{"name":"The Stdlib Authors","url":"https://github.com/stdlib-js/stdlib/graphs/contributors"}],"maintainers":[{"name":"stdlib-bot","email":"kgryte+stdlibbot@gmail.com"},{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},{"name":"rreusser","email":"rsreusser@gmail.com"}],"readme":"<!--\n\n@license Apache-2.0\n\nCopyright (c) 2018 The Stdlib Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n-->\n\n\n<details>\n  <summary>\n    About stdlib...\n  </summary>\n  <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>\n  <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>\n  <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>\n  <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href=\"https://github.com/stdlib-js/stdlib\">GitHub</a>, and please consider <a href=\"https://opencollective.com/stdlib\">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>\n</details>\n\n# Object Inverse\n\n[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->\n\n> Invert an object, such that keys become values and values become keys.\n\n<section class=\"installation\">\n\n## Installation\n\n```bash\nnpm install @stdlib/object-inverse\n```\n\n</section>\n\n<section class=\"usage\">\n\n## Usage\n\n```javascript\nvar invert = require( '@stdlib/object-inverse' );\n```\n\n#### invert( obj\\[, options] )\n\nInverts an `object`, such that keys become values and values become keys.\n\n```javascript\nvar out = invert({\n    'a': 'beep',\n    'b': 'boop'\n});\n// returns { 'beep': 'a', 'boop': 'b' }\n```\n\nThe function accepts the following `options`:\n\n-   **duplicates**: `boolean` indicating whether to store keys mapped to duplicate values in `arrays`. Default: `true`.\n\nBy default, keys mapped to duplicate values are stored in `arrays`.\n\n```javascript\nvar out = invert({\n    'a': 'beep',\n    'b': 'beep'\n});\n// returns { 'beep': [ 'a', 'b' ] }\n```\n\nTo **not** allow duplicates, set the `duplicates` option to `false`. The output `key-value` pair will be the `key` most recently inserted into the input `object`.\n\n```javascript\nvar obj = {};\nobj.a = 'beep';\nobj.b = 'boop';\nobj.c = 'beep'; // inserted after `a`\n\nvar out = invert( obj, {\n    'duplicates': false\n});\n// returns { 'beep': 'c', 'boop': 'b' }\n```\n\n</section>\n\n<!-- /.usage -->\n\n<section class=\"notes\">\n\n## Notes\n\n-   Beware when providing `objects` having values which are themselves `objects`. This implementation relies on native `object` serialization (`#toString`) when converting values to keys.\n\n    ```javascript\n    var obj = {\n        'a': [ 1, 2, 3 ],\n        'b': {\n            'c': 'd'\n        }\n    };\n\n    var out = invert( obj );\n    // returns { '1,2,3': 'a', '[object Object]': 'b' }\n    ```\n\n-   Insertion order is not guaranteed, as `object` key enumeration is not specified according to the [ECMAScript specification][ecma-262-for-in]. In practice, however, most engines use insertion order to sort an `object`'s keys, thus allowing for deterministic inversion.\n\n</section>\n\n<!-- /.notes -->\n\n<section class=\"examples\">\n\n## Examples\n\n<!-- eslint no-undef: \"error\" -->\n\n```javascript\nvar discreteUniform = require( '@stdlib/random-array-discrete-uniform' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar invert = require( '@stdlib/object-inverse' );\n\n// Create an array of random integers:\nvar arr = discreteUniform( 1000, 0, 100 );\n\n// Invert the array to determine value frequency:\nvar out = invert( arr );\nvar keys = objectKeys( out );\n\n// Compute the frequencies...\nvar i;\nfor ( i = 0; i < keys.length; i++ ) {\n    if ( out[ i ] ) {\n        out[ i ] = out[ i ].length;\n    } else {\n        out[ i ] = 0;\n    }\n}\nconsole.dir( out );\n```\n\n</section>\n\n<!-- /.examples -->\n\n<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->\n\n<section class=\"related\">\n\n* * *\n\n## See Also\n\n-   <span class=\"package-name\">[`@stdlib/object-inverse-by`][@stdlib/object/inverse-by]</span><span class=\"delimiter\">: </span><span class=\"description\">invert an object, such that keys become values and values become keys, according to a transform function.</span>\n\n</section>\n\n<!-- /.related -->\n\n<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n\n<section class=\"main-repo\" >\n\n* * *\n\n## Notice\n\nThis package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.\n\nFor more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].\n\n#### Community\n\n[![Chat][chat-image]][chat-url]\n\n---\n\n## License\n\nSee [LICENSE][stdlib-license].\n\n\n## Copyright\n\nCopyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].\n\n</section>\n\n<!-- /.stdlib -->\n\n<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->\n\n<section class=\"links\">\n\n[npm-image]: http://img.shields.io/npm/v/@stdlib/object-inverse.svg\n[npm-url]: https://npmjs.org/package/@stdlib/object-inverse\n\n[test-image]: https://github.com/stdlib-js/object-inverse/actions/workflows/test.yml/badge.svg?branch=v0.1.1\n[test-url]: https://github.com/stdlib-js/object-inverse/actions/workflows/test.yml?query=branch:v0.1.1\n\n[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/object-inverse/main.svg\n[coverage-url]: https://codecov.io/github/stdlib-js/object-inverse?branch=main\n\n<!--\n\n[dependencies-image]: https://img.shields.io/david/stdlib-js/object-inverse.svg\n[dependencies-url]: https://david-dm.org/stdlib-js/object-inverse/main\n\n-->\n\n[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg\n[chat-url]: https://stdlib.zulipchat.com\n\n[stdlib]: https://github.com/stdlib-js/stdlib\n\n[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors\n\n[umd]: https://github.com/umdjs/umd\n[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\n\n[deno-url]: https://github.com/stdlib-js/object-inverse/tree/deno\n[deno-readme]: https://github.com/stdlib-js/object-inverse/blob/deno/README.md\n[umd-url]: https://github.com/stdlib-js/object-inverse/tree/umd\n[umd-readme]: https://github.com/stdlib-js/object-inverse/blob/umd/README.md\n[esm-url]: https://github.com/stdlib-js/object-inverse/tree/esm\n[esm-readme]: https://github.com/stdlib-js/object-inverse/blob/esm/README.md\n[branches-url]: https://github.com/stdlib-js/object-inverse/blob/main/branches.md\n\n[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/object-inverse/main/LICENSE\n\n[ecma-262-for-in]: https://262.ecma-international.org/5.1/#sec-12.6.4\n\n<!-- <related-links> -->\n\n[@stdlib/object/inverse-by]: https://www.npmjs.com/package/@stdlib/object-inverse-by\n\n<!-- </related-links> -->\n\n</section>\n\n<!-- /.links -->\n","readmeFilename":"README.md"}