0.6.1 • Published 12 months ago

deep-key-mirror v0.6.1

Weekly downloads
3
License
MIT
Repository
github
Last release
12 months ago

Deep Key Mirror

npm version License CI

Alternative to React's keyMirror which further mirrors properties deep inside the object graph.

Installation

npm install deep-key-mirror

Usage

deepKeyMirror(obj)

Returns a new object that has values equal to its property names in the given object.

Simple example

import deepKeyMirror from 'deep-key-mirror';

deepKeyMirror({ name: '', 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.

Nested example

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' },
  ]
}
*/

TypeScript

TypeDoc-generated documentation is available here

0.5.4

12 months ago

0.5.3

12 months ago

0.5.5

12 months ago

0.5.0

12 months ago

0.6.1

12 months ago

0.5.2

12 months ago

0.6.0

12 months ago

0.5.1

12 months ago

0.3.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago