ob-map
![npm](https://img.shields.io/npm/dt/ob-map.svg)
Simple object mapper for creating flat javascript objects.
Description
Maps an object to a flat structure.
Map object keys from one key to another with the help of a mapping object.
Supports mapping of a nested object to a flat structure.
Installation
npm
npm install --save ob-map
yarn
yarn add ob-map
Usage
Flat Structure
import { map } from 'ob-map';
map(
{
a: 1,
b: 2
},
{
y: 'a',
z: 'b'
}
);
Nested Structure
import { map } from 'ob-map';
const obj = {
a: {
b: {
c: 1
}
},
d: {
e: 2
}
};
const mapping = {
x: 'a.b.c',
y: 'd.e'
};
map(obj, mapping);
Bulk Map
import { bulkMap } from 'ob-map';
const arr = [
{
a: 1,
b: 2,
c: 3
},
{
a: 3,
b: 4,
c: 5
}
];
const mapping = {
x: 'a',
y: 'b',
z: 'c'
};
bulkMap(arr, mapping);