babel-plugin-objective-enums
Babel plugin allowing to use enum syntax in JavaScript projects. It wraps objective-enums and it requires Babel 7.
Some code fragments are from babel-plugin-transform-typescript.
Installation
$ npm install --save-dev babel-plugin-objective-enums
Usage
.babelrc
(Recommended)
Via .babelrc
Via CLI
$ babel --plugins babel-plugin-objective-enums script.js
Via Node API
;
All-in-one Example
// Get color value and nameconsole.logColors.Red.value + ' - ' + Colors.Red.toString; // #FF0000 - Red // Only green and blue are allowed colors; // Get names of allowed colorsconsole.logColors.matchallowed; // ["Green", "Blue"] // Add yellow to allowed colorsallowed |= Colors.Yellow;console.logColors.matchallowed; // ["Green", "Blue", "Yellow"] // Remove blue from allowed colorsallowed &= ~Colors.Blue;console.logColors.matchallowed; // ["Green", "Yellow"] // Get common elements' names of allowed and selected colors;console.logColors.intersectallowed, selectedColors; // ["Yellow"]