https://github.com/shijistar/enum-plus
A drop-in replacement for native enum. Like native enum, but much better!
https://github.com/shijistar/enum-plus
back-end enum enumeration front-end internationalization reactjs vuejs
Last synced: 12 days ago
JSON representation
A drop-in replacement for native enum. Like native enum, but much better!
- Host: GitHub
- URL: https://github.com/shijistar/enum-plus
- Owner: shijistar
- License: mit
- Created: 2022-10-05T14:46:35.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2026-05-28T12:56:27.000Z (15 days ago)
- Last Synced: 2026-05-28T14:22:16.445Z (15 days ago)
- Topics: back-end, enum, enumeration, front-end, internationalization, reactjs, vuejs
- Language: TypeScript
- Homepage: https://shijistar.github.io/enum-plus
- Size: 36.4 MB
- Stars: 186
- Watchers: 1
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
[English](./README.md) | [中文](./README.zh-CN.md) | [CHANGELOG](./CHANGELOG.md)
Like native enum, but much better!
A solution for business dictionary management.
[](https://www.npmjs.com/package/enum-plus)
[](https://www.npmjs.com/package/enum-plus?activeTab=code)
[](https://www.npmjs.com/package/enum-plus)
[](https://deepwiki.com/shijistar/enum-plus)
[](https://app.codecov.io/gh/shijistar/enum-plus)

**Supported Platforms**
[](https://www.npmjs.com/package/enum-plus)
[](https://github.com/shijistar/enum-plus)
[](https://reactnative.dev)
[](https://developers.weixin.qq.com/miniprogram/en/dev/framework)
[](https://docs.taro.zone/en/docs)
[Introduction](https://shijistar.github.io/enum-plus/?path=/docs/introduce--docs) • [Get Started](https://shijistar.github.io/enum-plus/?path=/docs/get-started--docs) • [API Reference](https://shijistar.github.io/enum-plus/?path=/docs/api--docs) • [Global Configuration](https://shijistar.github.io/enum-plus/?path=/docs/global-configuration--docs) • [User Stories](https://shijistar.github.io/enum-plus/?path=/docs/user-stories--docs) • [Plugin System](https://shijistar.github.io/enum-plus/?path=/docs/plugin-system--docs) • [Localization](https://shijistar.github.io/enum-plus/?path=/docs/localization--docs) • [Extensibility](https://shijistar.github.io/enum-plus/?path=/docs/extensibility--docs) • [Best Practices](https://shijistar.github.io/enum-plus/?path=/docs/best-practices--docs) • [Compatibility](https://shijistar.github.io/enum-plus/?path=/docs/compatibility--docs) • [FAQ](https://shijistar.github.io/enum-plus/?path=/docs/faq--docs)
## Why enum-plus
Native enums are great for constants, but product code usually needs more at runtime:
- human-readable label,
- metadata such as color, icon, or permission
- dropdowns, checkboxes, and menus,
- table filters,
- render a label in a table,
- render a badge color,
- localization,
- metadata lookups,
- validation and lookup helpers.
`enum-plus` keeps the direct enum-style experience, then adds those runtime capabilities in one place.
It's a front-end business dictionary solution, that provides a lightweight data source. It's part of the front-end infrastructure.
## Features
- Compatible with the usage of native enums
- Supports multiple data types such as `number` and `string`
- Enhanced enum items with display names
- Internationalization support for display names, can be integrated with any i18n library
- Converts values directly into display names, simplifying data display in the UI
- Extensible design, allowing custom metadata fields for enum items
- Plugin system design, extending enum functionality through plugin installations
- Supports type narrowing to enhance type safety_ TypeScript_
- Generates dropdowns from enums, compatible with UI libraries like [Ant Design](https://ant.design/components/overview), [Element Plus](https://element-plus.org/en-US/component/overview), [Material-UI](https://mui.com/material-ui)
- Compatible with various environments including Browsers, Node.js, React Native, Taro, and mini-programs
- Supports server-side rendering (SSR)
- Compatible with any front-end development framework, including vanilla projects
- TypeScript‑oriented, providing excellent type inference and code completion capabilities
- Zero dependencies
- Lightweight (min+gzip 2KB+ only)
## Installation
```bash
npm install enum-plus
```
## Quick example
```ts
import { Enum } from 'enum-plus';
const StatusEnum = Enum({
Draft: { value: 1, label: 'Draft', color: 'default' },
Review: { value: 2, label: 'In Review', color: 'processing' },
Published: { value: 3, label: 'Published', color: 'success' },
});
StatusEnum.Review; // 2
StatusEnum.label(2); // 'In Review'
StatusEnum.key(2); // 'Review'
StatusEnum.items; // [{ key: 'Draft', value: 1, label: 'Draft' }, ...]
StatusEnum.values; // [1, 2, 3]
StatusEnum.labels; // ['Draft', 'In Review', 'Published']
StatusEnum.meta; // { color: [ 'default', 'processing', 'success' ] }
StatusEnum.findBy('color', 'success')?.key; // 'Published'
StatusEnum.toList({ valueField: 'value', labelField: 'label' }); // [{ value: 1, label: 'Draft' }, ...]
```
## Ecosystem
- [@enum-plus/plugin-react](./packages/plugin-react/README.zh-CN.md)
- [@enum-plus/plugin-react-i18next](./packages/plugin-react-i18next/README.zh-CN.md)
- [@enum-plus/plugin-i18next](./packages/plugin-i18next/README.zh-CN.md)
- [@enum-plus/plugin-i18next-vue](./packages/plugin-i18next-vue/README.zh-CN.md)
- [@enum-plus/plugin-vue-i18n](./packages/plugin-vue-i18n/README.zh-CN.md)
- [@enum-plus/plugin-next-international](./packages/plugin-next-international/README.zh-CN.md)
- [@enum-plus/plugin-antd](./packages/plugin-antd/README.zh-CN.md)
## Support
If this project helps you, please consider giving it a [star ⭐️](https://github.com/shijistar/enum-plus) on GitHub. This will encourage us to continue developing and maintaining this project.