https://github.com/tylim88/swob
Swap object key abd value with correct typing
https://github.com/tylim88/swob
Last synced: about 2 months ago
JSON representation
Swap object key abd value with correct typing
- Host: GitHub
- URL: https://github.com/tylim88/swob
- Owner: tylim88
- License: mit
- Created: 2021-10-14T02:52:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-06T08:52:55.000Z (over 3 years ago)
- Last Synced: 2025-03-13T09:48:16.339Z (2 months ago)
- Language: JavaScript
- Size: 612 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# swob
[](https://www.npmjs.com/package/swob) [](https://github.com/tylim88/swob/blob/main/LICENSE) [](<[LINK](https://github.com/tylim88/swob#swob)>)
🐤 swap object key and value and return accurate type.
🥰 0 dependency.
⛲️ Out of box typescript support.
🦺 Tested.
## Installation
```bash
npm i swob
```## Usage
🎵 Usage
```ts
import swob from 'swob'const swapped = swob({ a: '1' as const, b: '2' as const, c: '3' as const })
console.log(swapped) // {'1': 'a','2': 'b','3': 'c'}
type swapped = typeof swapped // {'1': 'a','2': 'b','3': 'c'}
```Important, you must use `const assertion` as shown in above example!
return new object, does not modify original object