diff --git a/README.md b/README.md index ce46145..5e9ee56 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,15 @@ Input: `{key1: val1, key2: val2}` Output: `{key1: key1, key2: key2}` +You can specify the prefix for all values: + +```javascript +keyMirror({ + OPEN: null, + CLOSE: null +}, 'WINDOW_'); +``` + I sometimes use this with lodash - use the following upon your first use of lodash to mix it in: ```javascript diff --git a/index.js b/index.js index 7f657b9..1195d6c 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,8 @@ * @param {object} obj * @return {object} */ -var keyMirror = function(obj) { +var keyMirror = function(obj, prefix) { + prefix = prefix || ''; var ret = {}; var key; if (!(obj instanceof Object && !Array.isArray(obj))) { @@ -43,7 +44,7 @@ var keyMirror = function(obj) { } for (key in obj) { if (obj.hasOwnProperty(key)) { - ret[key] = key; + ret[key] = prefix + key; } } return ret;