5outh / enumy

Tiny npm module for making enums from arrays of strings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enumy

A tiny npm module for creating basic enumerables.

Usage

var enumy = require('enumy');

var Planets = enumy(
    'PLANET_MERCURY',
    'PLANET_VENUS',
    'PLANET_EARTH',
    'PLANET_MARS',
    'PLANET_JUPITER',
    'PLANET_SATURN',
    'PLANET_URANUS',
    'PLANET_NEPTUNE'
);

console.log(Planets.PLANET_MERCURY);
// #=> 'PLANET_MERCURY'

A common pattern is to expose an enum as a module. To do this, just tack on:

module.exports = Planets

to the above file, then you can require('./path/to/Planets.js') and use the enum wherever you'd like.

That's it!

About

Tiny npm module for making enums from arrays of strings

License:MIT License


Languages

Language:JavaScript 100.0%