enumerify

1.0.2 • Public • Published

Enumerify

An enum type for JavaScript whose API simply exposes two types of enums: a string enum or a numeric enum. Works in Node and the Browser.

Usage

npm install --save-dev enumerify

You can create two types of enums:

Numeric Enums:

const Enumerify = require("enumerify");
 
... 
 
const numericEnum = new Enumerify({isStringEnum: false}, ["Up", "Down", "Left", "Right"]);
numericEnum.Up
// => 0

String Enums:

String enums values must be manually set for each member, and can be anything you want.

const Enumerify = require("enumerify");
 
...
 
const stringEnum = new Enumerify({isStringEnum: true}, {Up: "1", Down: "2", Left: "3", Right: "4"});
stringEnum.Up
// => "1"

Notes

There are many ways to create enums in JavaScript, but for the most part you have to fake it and you will not get type safety :)

Package Sidebar

Install

npm i enumerify

Weekly Downloads

6

Version

1.0.2

License

MIT

Unpacked Size

4.72 kB

Total Files

5

Last publish

Collaborators

  • ahadb