safe-enum

1.0.2 • Public • Published

Safe Enum

Define enums as a getter function, so you'll get descriptive runtime exceptions not undefined if you make a typo.

var enums = require("safe-enum");

exports.dateFormats = enums("usUk", "uk", "long");
exports.dateFormatsFromObject = enums({
  "US_UK": "usUk",
  "UK": "gb"
});

exports.dateFormats("usUk"); // usUk
exports.dateFormats("uUk"); // Error

exports.dateFormatsFromObject("UK"); // 'gb'

This is for constants you'll expose in a module - for internal constants, it's easier to define as var SOME_CONSTANT = 'blah' and use jshint to references to undeclared variables.

Install

npm i -S safe-enum

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i safe-enum

      Weekly Downloads

      1

      Version

      1.0.2

      License

      MIT

      Last publish

      Collaborators

      • timruffles