1.0.4 • Published 4 years ago

enum-array v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

enum-array

typescript枚举数组化

截图

1

说明

typescript枚举很高级,会自动生成一个key和value可逆的数据对象,但它本身不是一个可遍历的数据,我们在使用时有很多限制,于是我们将枚举重新包装成一个键值对的数组,可循环,数据且不重复。

安装

$ npm install enum-array

引入模块

import enumArray from 'enum-array'

使用方法

/**
 * 原始枚举
 */
enum Citys {
  北京 = 10,
  上海 = 21,
  广州 = 20
}

/**
 * 枚举数组化
 */
enumArray.getEnumArray(Enum)
// enumArray.getEnumArray(Citys)

/**
 * 从可枚举数组中取值
 */
enumArray.getValueByEnum(key, getEnumArray(Enum))
// EnumArray.getValueByEnum(10, getEnumArray(Citys))

方法

事件名说明参数
getEnumArray枚举数组化枚举
getValueByEnum从可枚举数组中取值键,枚举数组