Skip to content

awndrw/Enumer8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enumer8

A Simple Node.js Enumeration Library

npm version Dependency Status Build Status

Table of Contents

$ npm i enumer8
import Enum from 'enumer8'

let Pets = new Enum()
Pets.case('Dog', 'Cat', 'Fish')

console.log(Pets.Dog) // { id:'Dog' , rawValue:'Dog' }

Pets.case('Lizard')
console.log(Pets.Lizard) // { id:'Lizard' , rawValue:'Lizard' }
console.log(Pets.Cat) // { id:'Cat' , rawValue:'Cat' }

Each enumeration can be configured on instantiation:

new Enum({ /* ... */ })

Alternatively, the config parameter can be used to initialize an enumeration of a set type (see type configuration):

new Enum('string')
{ type: 'string' }

The type option can be set to a string type ('string', 'number', ...) or false. If raw values are not provided, they will be created according to the specified type.
Example:

let PetNames = new Enum('string')

PetNames.case({
	Dog: 'Bolt',
	Cat: 'Simba',
	Mouse: 'Mickey'
})

PetNames.case({ Snake: true }) // Throws TypeError

.case()

  • The main method for enumerations.
  • The case(s) provided must be strings, an array of strings, or an object

.freeze()

  • Freezes the current enumeration, preventing the modification of values.

MIT © Andrew Wiggin

About

A Simple Node.js Enumeration Library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published