Github Like native enum, but much better!   Introduction | Features | Installation | Enum Definition | API | Usage | Localization | Global Extension Introduction enum-plus is an enhanced enum library that is fully compatible with the native enum and extends it with powerful features such as display text, localization, UI control binding, enum items traversal, and more useful extension methods. This lightweight, zero-dependency, TypeScript library works with any front-end framework. With the extended display text capability, enum items can be used to generate dropdowns, checkboxes, and other UI controls with a single line of code. By using the extension methods of the enum, you can easily traverse the array of enum items, get the display text of a certain enum value, determine whether a value exists, etc. The display text of the enum item supports localization, which can return the corresponding text according to the current language environment, making the display text of the enum item more flexible and more in line with user needs. What other exciting features are there? Please continue to explore! Or you can check out this usage video first. Features Full compatibility with native enum behavior Support for multiple data types including number and string Enhanced enum items with customizable display text Built-in localization capabilities that integrate with any i18n library Streamlined conversion from enum values to human-readable display text Extensible design allowing unlimited custom fields on enum items Seamless integration with any UI libraries like Ant Design, ElementPlus, Material-UI, in a single line of code Complete Node.js compatibility with SSR support Zero dependencies - pure JavaScript implementation usable in any front-end framework First-class TypeScript support with comprehensive type inference Lightweight (only 2KB+ gzipped) Installation npm install enum-plus Enum Definition Creates an enum, enum values support both number and string types. • Creates using the native style import { Enum } from 'enum-plus'; const Week = Enum({ Sunday: 0, Monday: 1, } as const); Week.Monday; // 1 • Creates using key, value, and display text

Apr 27, 2025 - 07:31
 0

Github

enum-plus
Like native enum, but much better!

 

Introduction | Features | Installation | Enum Definition | API | Usage | Localization | Global Extension

Introduction

enum-plus is an enhanced enum library that is fully compatible with the native enum and extends it with powerful features such as display text, localization, UI control binding, enum items traversal, and more useful extension methods. This lightweight, zero-dependency, TypeScript library works with any front-end framework.

With the extended display text capability, enum items can be used to generate dropdowns, checkboxes, and other UI controls with a single line of code. By using the extension methods of the enum, you can easily traverse the array of enum items, get the display text of a certain enum value, determine whether a value exists, etc. The display text of the enum item supports localization, which can return the corresponding text according to the current language environment, making the display text of the enum item more flexible and more in line with user needs.

What other exciting features are there? Please continue to explore! Or you can check out this usage video first.

Features

  • Full compatibility with native enum behavior
  • Support for multiple data types including number and string
  • Enhanced enum items with customizable display text
  • Built-in localization capabilities that integrate with any i18n library
  • Streamlined conversion from enum values to human-readable display text
  • Extensible design allowing unlimited custom fields on enum items
  • Seamless integration with any UI libraries like Ant Design, ElementPlus, Material-UI, in a single line of code
  • Complete Node.js compatibility with SSR support
  • Zero dependencies - pure JavaScript implementation usable in any front-end framework
  • First-class TypeScript support with comprehensive type inference
  • Lightweight (only 2KB+ gzipped)

Installation

npm install enum-plus

Enum Definition

Creates an enum, enum values support both number and string types.

• Creates using the native style

import { Enum } from 'enum-plus';

const Week = Enum({
  Sunday: 0,
  Monday: 1,
} as const);

Week.Monday; // 1

• Creates using key, value, and display text