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 = ; ... const numericEnum = isStringEnum: false "Up" "Down" "Left" "Right";numericEnumUp// => 0
String Enums:
String enums values must be manually set for each member, and can be anything you want.
const Enumerify = ; ... const stringEnum = isStringEnum: true Up: "1" Down: "2" Left: "3" Right: "4";stringEnumUp// => "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 :)