# enumify

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

Latest version **2.0.0** (published 2020-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install enumify
pnpm add enumify
yarn add enumify
bun add enumify
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-01-13 |
| First published | 2016-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 663 |
| Author | Axel Rauschmayer |
| Maintainers | rauschma |

## Links

- npm: https://www.npmjs.com/package/enumify
- Repository: https://github.com/rauschma/enumify
- Homepage: https://github.com/rauschma/enumify#readme
- Issues: https://github.com/rauschma/enumify/issues
- npm.io page: https://npm.io/package/enumify

## Recent versions

- 2.0.0 (latest) — 2020-01-13
- 1.0.4 — 2016-01-20
- 1.0.3 — 2016-01-19
- 1.0.2 — 2016-01-14
- 1.0.1 — 2016-01-14
- 1.0.0 — 2016-01-14

## README

# Enumify

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

Installation:

```text
npm install enumify
```

## Basic usage

```ts
  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
```

---
_Source: https://npm.io/package/enumify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
