reflectkeys
v1.0.3
Published
A succinct way to create an object with mirrored keys and values
Downloads
3
Readme
reflectkeys
Create an object with values that mirror its keys from a string of whitespace-separated keys
Usage
npm install reflectkeys
var reflectKeys = require('reflectkeys');
var mirrorObject = reflectKeys("A B C");
// mirrorObject = { A: 'A', B: 'B', C: 'C' }
Input: "key1 key2 key3"
Output: {key1: key1, key2: key2, key: key3}
I use it instead of keyMirror for defining flux ActionTypes, eg:
// TodoActionTypes.js
import reflectKeys from 'reflectkeys';
const TodoActionTypes = reflectKeys(`TODO_ADD
TODO_UPDATE
TODO_DELETE`);
export default TodoActionTypes;