0.1.8 • Published 7 years ago
enumify-js v0.1.8
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!