enum-xyz
JavaScript enums using proxies.
Based on this tweet
Install
$ npm install enum-xyz --save
Usage
Strings
const Enum = require('./index')
const { Summer, Autumn, Winter, Spring } = Enum.String
console.log(Summer) // 'Summer'
console.log(Autumn) // 'Autumn'
console.log(Winter) // 'Winter'
console.log(Spring) // 'Spring'
Strings (lowercased)
const Enum = require('./index')
const { Summer, Autumn, Winter, Spring } = Enum.StringLower
console.log(Summer) // 'summer'
console.log(Autumn) // 'autumn'
console.log(Winter) // 'winter'
console.log(Spring) // 'spring'
Numeric
const Enum = require('./index')
const { A, B, C, D } = Enum.String
console.log(A) // 0
console.log(B) // 1
console.log(C) // 2
console.log(D) // 3
Numeric Starting at Index
const Enum = require('./index')
const { A, B, C, D } = Enum.NumericAt(1)
console.log(A) // 1
console.log(B) // 2
console.log(C) // 4
console.log(D) // 4