enumify

WebJar for enumify

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

enumify
Последняя версия

Последняя версия

1.0.4
Дата

Дата

Тип

Тип

jar
Описание

Описание

enumify
WebJar for enumify
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/rauschma/enumify

Скачать enumify

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/enumify/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>enumify</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/enumify/
implementation 'org.webjars.npm:enumify:1.0.4'
// https://jarcasting.com/artifacts/org.webjars.npm/enumify/
implementation ("org.webjars.npm:enumify:1.0.4")
'org.webjars.npm:enumify:jar:1.0.4'
<dependency org="org.webjars.npm" name="enumify" rev="1.0.4">
  <artifact name="enumify" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='enumify', version='1.0.4')
)
libraryDependencies += "org.webjars.npm" % "enumify" % "1.0.4"
[org.webjars.npm/enumify "1.0.4"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Enumify

A JavaScript library that helps with the enum pattern. Also supports TypeScript.

Installation:

npm install enumify

Basic usage

  class Color extends Enumify {
    static red = new Color();
    static orange = new Color();
    static yellow = new Color();
    static green = new Color();
    static blue = new Color();
    static purple = new Color();
    static _ = this.closeEnum(); // TypeScript: Color.closeEnum()
  }

  // Instance properties
  assert.equal(
    Color.red.enumKey, 'red');
  assert.equal(
    Color.red.enumOrdinal, 0);
  
  // Prototype methods
  assert.equal(
    'Color: ' + Color.red, // .toString()
    'Color: Color.red');
  
  // Static `.enumKeys` and static `.enumValues`
  assert.deepEqual(
    Color.enumKeys,
    ['red', 'orange', 'yellow', 'green', 'blue', 'purple']);
  assert.deepEqual(
    Color.enumValues,
    [ Color.red, Color.orange, Color.yellow,
      Color.green, Color.blue, Color.purple ]);

  // Static `.enumValueOf()`
  assert.equal(
    Color.enumValueOf('yellow'),
    Color.yellow);
  
  // Iterability
  const result = [];
  const iterated = [...Color];
  for (const c of Color) {
    result.push('Color: ' + c);
  }
  assert.deepEqual(
    iterated, [
      Color.red,
      Color.orange,
      Color.yellow,
      Color.green,
      Color.blue,
      Color.purple,
    ]);

More examples

See:

  • ts/test/index_test.ts
  • ts/test/state.ts

Run tests like this (after compiling TypeScript, e.g. via npm run build):

npm t dist/test/index_test.js

Support for public static fields

The enum pattern and Enumify are based on public static fields. Support for them currently looks as follows:

Further reading

Версии библиотеки

Версия
1.0.4