1.3.0 • Published 8 years ago

nu-enum v1.3.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

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

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago