gulp-transform-enum
A plugin for gulp that will compile Java-style enums down to Javascript. Maps to strings, not integers.
Installation
$ npm install gulp-transform-enum --save-dev
Use case
This plugin will extend the Javascript language with enums like you know them from Java.
Here's the syntax you can now use:
This compiles down to the following ES2015 code:
const Gender = MALE: "MALE" FEMALE: "FEMALE" UNKNOWN: "UNKNOWN"
If you're using babel to support experimental class fields, this plugin will also allow you to define static enums inside the body of a class:
static enum Gender MALE FEMALE UNKNOWN //Rest of body here
It will compile down to:
static Gender = MALE: "MALE" FEMALE: "FEMALE" UNKNOWN: "UNKNOWN" //Rest of body here
Enums are NOT part of the official ES2015 module spec. Be aware that the syntax this plugin expects isn't and probably never will be officially supported.
Usage
Simply add it to your gulpfile.js
:
const ENUM_EXTENSION = ; gulp ;
License
Copyright (c) 2016 Dlmma IVS. Released under the MIT license.