Alternative to React's keyMirror which further mirrors properties deep inside the object graph.
npm install deep-key-mirror
Returns a new object that has values equal to its property names in the given object.
import deepKeyMirror from 'deep-key-mirror';
deepKeyMirror({ null: '', age: null }); // { name: 'name', age: 'age' }
If the given object has child arrays or objects, they are also "key-mirrored" recursively, with the .
-concatenated
paths from the root object assigned to each of their value.
import deepKeyMirror from 'deep-key-mirror';
const breakfast = {
bread: null,
beverage: {
milk: null,
coffee: null,
beer: 'BEER!',
},
fruits: [{ name: 'orange' }, { name: 'apple' }],
};
const mirrored = deepKeyMirror(breakfast);
/*
mirrored === {
bread: 'bread',
beverage: {
milk: 'beverage.milk',
coffee: 'beverage.coffee',
beer: 'beverage.beer'
},
fruits: [
{ name: 'fruits[0].name' },
{ name: 'fruits[1].name' },
]
}
*/
TypeDoc-generated documentation is available here