@hwdcc/enum-type
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@hwdcc/enum-type

介绍

JavaScript 枚举管理

安装教程

  # pnpm
  pnpm add @hwdcc/enum-type
  # yarn
  yarn add @hwdcc/enum-type
  # npm 
  npm i -s @hwdcc/enum-type

使用说明

  // EAdStatus.js
  import { Enum, enumClass, enumComment } from '@cc/enum-type'

  @enumClass
  class EAdStatus extends Enum {
    @enumComment('草稿', 'is-info')
    static STATUS_1 = 1

    @enumComment('审核中', 'is-warning')
    static STATUS_2 = 2

    @enumComment('审核不通过', 'is-danger')
    static STATUS_3 = 3
  }

  export default EAdStatus;

接口方法

Enum.$toCommentList

  EAdStatus.$toCommentList()
  // [{id: 1, name: '草稿'},{id: 2, name: '审核中'},{id: 3, name: '审核不通过'}]

Enum.$toCommentMapWithValue

  EAdStatus.$toCommentMapWithValue()
  // {1: '草稿', 2: '审核中', 3: '审核不通过'}

Enum.$toClassNamesMapWithValue

  EAdStatus.$toClassNamesMapWithValue()
  // {1: 'is-info', 2: 'is-warning', 3: 'is-danger'}

Enum.$toCommentMapWithKey

  EAdStatus.$toCommentMapWithKey()
  // {STATUS_1: '草稿', STATUS_2: '审核中', STATUS_3: '审核不通过'}

Enum.$comments

  EAdStatus.$comments
  //  即 EAdStatus.$toCommentList()
  // [{id: 1, name: '草稿'},{id: 2, name: '审核中'},{id: 3, name: '审核不通过'}]

Enum.$classNames

  EAdStatus.$classNames
  //  即 EAdStatus.$toClassNamesMapWithValue()
  // {1: 'is-info', 2: 'is-warning', 3: 'is-danger'}

Enum.$options

  EAdStatus.$options
  // 即 EAdStatus.$toCommentList()
  // [{id: 1, name: '草稿'},{id: 2, name: '审核中'},{id: 3, name: '审核不通过'}]

Enum.$toValueWithId

Enum.$toIdWithValue

Install

npm i @hwdcc/enum-type

DownloadsWeekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

31.2 kB

Total Files

14

Last publish

Collaborators

  • hwd_cc