UNPKG

key-mirror-nested

Version:

Tiny helper to create const in js, just like react/lib/keyMirror, but support nested object and more features.

32 lines (27 loc) 626 B
var keyMirrorDeep = require('./index'); var DUMMY_CONST = { ACTIONS: { LOGIN: { SUCCESS: null, ERROR: undefined }, ACTIONB: [1,2,'ghj'] }, EVENTS: { A: 123, B: 456 }, SOMEOTHER: 789 }; var res = keyMirrorDeep(DUMMY_CONST, { connChar: '_', custFunc: function(oldVal, newVal) { // you can do something with const val here if(typeof(oldVal) === "number") { newVal = newVal + '_' + oldVal } return newVal; } }) console.log(DUMMY_CONST); console.log(res);