
Security News
Inside Lodash’s Security Reset and Maintenance Reboot
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.
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 9 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.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.

Security News
n8n led JavaScript Rising Stars 2025 by a wide margin, with workflow platforms seeing the largest growth across categories.

Security News
The U.S. government is rolling back software supply chain mandates, shifting from mandatory SBOMs and attestations to a risk-based approach.