Skip to content

5outh/enumy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published