0.1.8 • Published 7 years ago

enumify-js v0.1.8

Weekly downloads
74
License
MIT
Repository
github
Last release
7 years ago

enumify-js

A library for easily creating enum-like objects in ES6.

Installation

npm install enumify-js

Import

const enumify = require('enumify-js')

Usage

create enum classes

const Animal = enumify('Cat', 'Dog', 'Fish')

check types of enum objects

Animal.Cat instanceof Animal   //true
Animal.Dog instanceof Animal   //true
Animal.Fish instanceof Animal  //true

compare enum objects

const {Cat, Dog, Fish} = Animal
Cat !== Dog   //true
Cat !== Fish  //true
Dog !== Fish  //true

convert to String

Cat.name   //'Cat'

get value (based on ordering)

Cat.value   //1
Dog.value   //2
Fish.value  //3

Immutability

cannot write to enum

Animal.SomethingElse = {}		//Error

cannot change enum objects

Animal.Cat = {}		//Error

cannot delete enum objects

delete Animal.Dog		//Error

Notes

Feedback, suggestions, and PRs are welcomed!

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago