GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - shijistar/enum-plus: A drop-in replacement for native enum. Like native enum, but much better!

BranchesTags
Open more actions menu

Latest commit

 

History

631 Commits
631 Commits

Folders and files

NameName
Last commit message
Last commit date
.claude
.claude
 
 
.github
.github
 
 
.husky
.husky
 
 
.storybook
.storybook
 
 
.vscode
.vscode
 
 
docs
docs
 
 
packages
packages
 
 
public
public
 
 
scripts
scripts
 
 
src
src
 
 
test
test
 
 
types-legacy/pre-v5
types-legacy/pre-v5
 
 
.coderabbit.yaml
.coderabbit.yaml
 
 
.fatherrc.ts
.fatherrc.ts
 
 
.gitignore
.gitignore
 
 
.ignore
.ignore
 
 
.mcp.json
.mcp.json
 
 
.prettierignore
.prettierignore
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README-FULL.md
README-FULL.md
 
 
README-FULL.zh-CN.md
README-FULL.zh-CN.md
 
 
README.md
README.md
 
 
README.zh-CN.md
README.zh-CN.md
 
 
SECURITY.md
SECURITY.md
 
 
commitlint.config.mjs
commitlint.config.mjs
 
 
eslint.config.mjs
eslint.config.mjs
 
 
jest-cjs.config.js
jest-cjs.config.js
 
 
jest-esm.config.js
jest-esm.config.js
 
 
jest-legacy.config.js
jest-legacy.config.js
 
 
jest.config.js
jest.config.js
 
 
lint-staged.config.mjs
lint-staged.config.mjs
 
 
opencode.json
opencode.json
 
 
package-legacy-node.json
package-legacy-node.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
prettier.config.mjs
prettier.config.mjs
 
 
stylelint.config.mjs
stylelint.config.mjs
 
 
tsconfig.es.json
tsconfig.es.json
 
 
tsconfig.eslint.json
tsconfig.eslint.json
 
 
tsconfig.json
tsconfig.json
 
 
tsconfig.lib.json
tsconfig.lib.json
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

English | 中文 | CHANGELOG

enum-plus

A solution for business dictionary management

Like native enum, but much better!


npm latest version npm package minimized gzipped size npm downloads Ask DeepWiki code coverage GitHub License

Supported Platforms

Web Browsers   Node compatibility   React Native   MiniProgram   Taro

Introduction • Get Started • API Reference • Global Configuration • User Stories • Plugin System • Localization • Extensibility • Best Practices • Compatibility • FAQ • Full API Reference

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.

usage video
↑ Click image for HD video ↑

💡 Want to see what enum-plus can do and how it improves productivity? See Full Demo

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, Element Plus, 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

npm install enum-plus

Quick example

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.Draft; // 1
StatusEnum.Review; // 2
StatusEnum.Published; // 3
StatusEnum.label(2); // 'In Review'
StatusEnum.has(2); // true
StatusEnum.keys; // ['Draft', 'Review', 'Published']
StatusEnum.values; // [1, 2, 3]
StatusEnum.labels; // ['Draft', 'In Review', 'Published']
StatusEnum.items; // [{ key: 'Draft', value: 1, label: 'Draft', color: 'default' }, ...]
StatusEnum.item(1); // { key: 'Draft', value: 1, label: 'Draft', color: 'default' }
StatusEnum.named.Draft; // { key: 'Draft', value: 1, label: 'Draft', color: 'default' }
StatusEnum.meta; // { color: [ 'default', 'processing', 'success' ] }
StatusEnum.findBy('color', 'success'); // { key: 'Published', value: 3, label: 'Published', color: 'success' }
StatusEnum.toList({ valueField: 'id', labelField: 'name' }); // [{ id: 1, name: 'Draft' }, ...]
StatusEnum.toMap({ keySelector: 'key', valueSelector: 'value' }); // { Draft: 1, Review: 2, Published: 3 }

i18n

import i18nPlugin from '@enum-plus/plugin-i18next';
import { Enum } from 'enum-plus';

Enum.install(i18nPlugin);

const StatusEnum = Enum({
  Draft: { value: 1, label: 'locales.enums.statusEnum.draft' },
  Review: { value: 2, label: 'locales.enums.statusEnum.review' },
  Published: { value: 3, label: 'locales.enums.statusEnum.published' },
});

StatusEnum.labels; // ['Draft', 'In Review', 'Published'] or ['草稿', '审核中', '已发布']
StatusEnum.label(2); // 'In Review' or '审核中'
StatusEnum.named.Review.label; // 'In Review' or '审核中'

Ecosystem

  • @enum-plus/plugin-react
  • @enum-plus/plugin-react-i18next
  • @enum-plus/plugin-i18next
  • @enum-plus/plugin-i18next-vue
  • @enum-plus/plugin-vue-i18n
  • @enum-plus/plugin-next-international
  • @enum-plus/plugin-antd

Support

If this project helps you, please consider giving it a Star ⭐️ on GitHub. This will encourage us to continue developing and maintaining this project.

About

A drop-in replacement for native enum. Like native enum, but much better!

shijistar.github.io/enum-plus/

Topics

backendenumenumerationfront-endinternationalizationreactjsvuejs

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

206 stars

Watchers

1 watching

Forks

10 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.