
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
Using npm:
$ npm install cenum
or using yarn:
$ yarn add cenum
import Enum from 'cenum';
const status = new Enum([
{name: 'ACTIVE', value: 1, label: '激活'},
{name: 'INACTIVE', value: 0, lable: '未激活'}
]);
status.get('ACTIVE').is(1); // true
status.get('ACTIVE').is('ACTIVE'); // true
status.get('ACTIVE').is('激活'); // true
status.has('INACTIVE'); // true
status.has(0); // true
status.has('未激活'); // true
status.get('ACTIVE').in(0, 1) // true
status.get('ACTIVE').in(['ACTIVE', '未激活']) // true
status.get('ACTIVE').label // 激活
status.get('ACTIVE').name // ACTIVE
status.get('ACTIVE').value // 0
除了通过 get 方法获取对应的枚举,还可以通过枚举名称直接获取,前提条件是枚举名称和内部变量不产生冲突,所以建议名称使用大写,因为内部变量都用的小写,保证不冲突
status.ACTIVE.label // 激活
或者使用parse批量转换
import { enums, parse } from 'cenum';
parse({
role: [
{name: 'ACTIVE', value: 1, label: '激活'},
{name: 'INACTIVE', value: 0, lable: '未激活'}
],
gender: [
['MALE', 1, '男'],
['FEMALE', 0, '女']
]
})
enums.role // 角色Enum
enums.gender // 性别Enum
构造方法的参数有四种格式
当缺失name或者label的时候,将自动用name表示label或者用label表示name
当name和label都没有的时候,将默认等于value
请确保每一条的name, value, label互相之间都是不一样的
FAQs
一个简易的enum库
The npm package cenum receives a total of 1 weekly downloads. As such, cenum popularity was classified as not popular.
We found that cenum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.