enum-nom-nommer

node v10.16.0
version: 1.0.0
endpointsharetweet
Create reflexsive enumerations out of JavaScript objects.
const assert = require('assert') const { enumFactory } = require('enum-nom-nommer')
const s = (object) => JSON.stringify(object, null, ' ')
Numeric enums
// A log level object with "weighted" values const level = { debug: 5, error: 0, http: 3, info: 2, silly: 6, verbose: 4, warn: 1 } // The numeric levelEnum we want const expectedLevelsEnum = { 0: 'error', 1: 'warn', 2: 'info', 3: 'http', 4: 'verbose', 5: 'debug', 6: 'silly', debug: 5, error: 0, http: 3, info: 2, silly: 6, verbose: 4, warn: 1 } // Create the new enum const logLevelEnum = enumFactory.create(level) assert.deepEqual(logLevelEnum, expectedLevelsEnum) console.log(`${s(logLevelEnum)} == ${s(expectedLevelsEnum)}`) var levelList = [ "error", "warn", "info", "http", "verbose", "debug", "silly" ] console.log(`${s(enumFactory.create(levelList))}`)
Loading…

no comments

    sign in to comment