https://github.com/nixjs/ts-enumify
Generates a enum (like an object) with keys and values based on the elements of an array.
https://github.com/nixjs/ts-enumify
array-to-enum enum enum-generator enumify
Last synced: 3 months ago
JSON representation
Generates a enum (like an object) with keys and values based on the elements of an array.
- Host: GitHub
- URL: https://github.com/nixjs/ts-enumify
- Owner: nixjs
- Created: 2024-05-06T06:11:48.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-06T07:38:01.000Z (about 1 year ago)
- Last Synced: 2025-03-05T17:51:14.432Z (4 months ago)
- Topics: array-to-enum, enum, enum-generator, enumify
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @nixjs23n6/ts-enumify
Generates a enum (like an object) with keys and values based on the elements of an array.
## Install
```shell [npm]
npm install @nixjs23n6/ts-enumify
``````shell [pnpm]
pnpm add @nixjs23n6/ts-enumify
``````shell [yarn]
yarn add @nixjs23n6/ts-enumify
``````shell [bun]
bun add -@nixjs23n6/ts-enumify
```## Example
```typescript
import { Enumify } from '@nixjs23n6/ts-enumify'const EnumKey = Enumify.generate(['ENUM1', 'ENUM2', 'ENUM3'] as const) // const EnumKey: Readonly>
type EnumType = keyof typeof EnumKey // type EnumType = "ENUM1" | "ENUM2" | "ENUM3"
```