New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

create-enum-es

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-enum-es

处理前端枚举的工具方法,支持ts类型检测

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source
import createEnum from "create-enum-es";

const base = createEnum({
  AA: [11, "AA-"],
  BB: [22, "BB-"],
} as const);

console.log("base.AA :>> ", base.AA);
// 11

console.log("base.BB :>> ", base.BB);
// 22

console.log("base.options() :>> ", base.options());
// [
//   {
//     "value": 11,
//     "label": "AA-"
//   },
//   {
//     "value": 22,
//     "label": "BB-"
//   }
// ]

const enumInstance = createEnum({
  A: [1, "A-", { a: "axx" }],
  B: [2, "B-", { b: "bxx" }],
} as const);

const value = enumInstance.value("A");
console.log("value :>> ", value);
// 1

const values = enumInstance.values();
console.log("values :>> ", values);
// [1, 2]

const options = enumInstance.options();
console.log("options :>> ", options);
// [
//   {
//     "value": 1,
//     "label": "A-",
//     "extra": {
//       "a": "axx"
//     }
//   },
//   {
//     "value": 2,
//     "label": "B-",
//     "extra": {
//       "b": "bxx"
//     }
//   }
// ]

const label = enumInstance.label("A");
console.log("label :>> ", label);
// 'A-'

const extra = enumInstance.extra("A");
console.log("extra :>> ", extra);
// {"a": "axx"}

const check = enumInstance.check(1, "A");
console.log("check :>> ", check);
// true

Keywords

enum

FAQs

Package last updated on 16 Jul 2025

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