🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More
Socket
Book a DemoInstallSign in
Socket

cenum

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cenum

一个简易的enum库

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
9
800%
Maintainers
1
Weekly downloads
 
Created
Source

cenum

安装

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.ACTIVE.is(1); // true
status.ACTIVE.is('ACTIVE'); // true
status.ACTIVE.is('激活'); // true

status.has('INACTIVE'); // true
status.has(0); // true
status.has('未激活'); // true

status.ACTIVE.label // 激活
status.ACTIVE.name // ACTIVE
status.ACTIVE.value // 0

or use 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, value, label互相之前都是不一样的

FAQs

Package last updated on 21 Mar 2019

Did you know?

Socket

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.

Install

Related posts