nu-enum

Create enum-like objects in JavaScript.


License
MIT
Install
npm install nu-enum@1.3.0

Documentation

nu-enum

npm version Build Status Codecov Dependency Status

Create enum-like objects in JavaScript.

Install

npm install nu-enum

Usage

nu-enum exposes a single function

Enum(...args: [...String]) => Enum

Creates an enum with properties args.

Enum properties will be an instance of their parent.

import Enum from 'nu-enum';

const RUNFLAGS = Enum('start', 'pause', 'stop');

RUNFLAGS.start instanceof RUNFLAGS // true
RUNFLAGS.pause instanceof RUNFLAGS // true
RUNFLAGS.stop instanceof RUNFLAGS // true

RUNFLAGS.start.toString(); // "start"

Enum properties are unique across enums.

import Enum from 'nu-enum';

const enumA = Enum('same');
const enumB = Enum('same');

enumA.same === enumB.same // false

Enum.add(arg: String) => Void

Add a property to the enum.

import Enum from 'nu-enum';

const ENUM = Enum('one', 'two', 'three');

ENUM.add('four');

ENUM.four instanceof ENUM // true

License

MIT