enumer8

2.0.0 • Public • Published

Enumer8

A Simple Node.js Enumeration Library

npm version Dependency Status Build Status

Table of Contents

Installation

$ npm i enumer8

Usage

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' }

Configuration

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')

Options ({option: default})

{ 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

API

.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.

License

MIT © Andrew Wiggin

Readme

Keywords

none

Package Sidebar

Install

npm i enumer8

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

39.6 kB

Total Files

24

Last publish

Collaborators

  • azwiggin