Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/terrysahaidak/mirror-to-object-pairs
Mirrors array elements as pairs of object key/value with typings.
https://github.com/terrysahaidak/mirror-to-object-pairs
Last synced: about 2 months ago
JSON representation
Mirrors array elements as pairs of object key/value with typings.
- Host: GitHub
- URL: https://github.com/terrysahaidak/mirror-to-object-pairs
- Owner: terrysahaidak
- License: mit
- Created: 2019-04-05T12:11:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-14T14:49:35.000Z (over 4 years ago)
- Last Synced: 2024-10-29T07:20:58.584Z (about 2 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mirror-to-object-pairs
[![npm](https://img.shields.io/npm/v/mirror-to-object-pairs.svg?style=plastic)](https://npmjs.com/package/mirror-to-object-pairs)
> Mirrors array elements as pairs of object key/value with typings.
## Installation
If you prefer npm:
```bash
npm i --save mirror-to-object-pairs
```If yarn is your way to go:
```bash
yarn add mirror-to-object-pairs
```## Usage
To get started, just import package and provide it an array of keys.
It will generate you paris in object with key/value of each element of passed array.```ts
import mirror from 'mirror-to-object-pairs';const pairs = mirror([
'FIRST',
'SECOND',
'third',
]);console.log(pairs.FIRST) // 'FIRST'
console.log(pairs.SECOND) // 'SECOND'
console.log(pairs.third) // 'third'
```## Usage with TS
```ts
import mirror from 'mirror-to-object-pairs';const Screens = mirror([
'Login',
'App',
])type Screens = keyof typeof Screens;
function navigate(screenName: T) {
// some logic
}navigate(screens.Login)
```Library provides typings so it works perfectly with TypeScript projects.
## License
[MIT](LICENSE) © Terry Sahaidak