node-mapper
NodeJS library for dot notation mapping
Install
npm install --save node-mapper
How to use
Just require as any other module
var mapper = ;
and use
where
- mapIn - string, array or object
- objectIn - object where we will perform lookup
- objectOut - optional object which will be extended on object mappings
any examples you can find below
TOC
String mapping
simple
var object = key: data: 'value' ;assert;
with array
var object = id: 'ID 1' id: 'ID 2' id: 'ID 3' ;assert;
with array 2
var object = id: 'ID 1' id: 'ID 2' id: 'ID 3' ;assert;
with array 3
var object = items: id: 1 datas: title: 'TITLE 1' title: 'TITLE 2' title: 'TITLE 3' id: 2 datas: title: 'TITLE 4' title: 'TITLE 5' ;assert;
with multiple arrays
var object = user: name: first: 'firstname1' last: 'lastname1' posts: id: 11 title: 'Post title 11' id: 12 title: 'Post title 12' id: 13 title: 'Post title 13' name: '0name' user: name: first: 'firstname2' last: 'lastname2' posts: id: 11 title: 'Post title 21' id: 12 title: 'Post title 22' id: 13 title: 'Post title 23' name: '1name' user: name: first: 'firstname3' last: 'lastname3' posts: id: 31 title: 'Post title 31' id: 32 title: 'Post title 32' id: 33 title: 'Post title 33' name: '2name' ;assert;
invalid path
var object = key: data: 'value' ;assert;
Array mapping
return array
var object = items: id: 1 datas: title: 'TITLE 1' title: 'TITLE 2' title: 'TITLE 3' id: 2 datas: title: 'TITLE 4' title: 'TITLE 5' ;assert;
trying to get index of non array
var object = key: data: 'value' ;assert;
Object mapping
simple object
var object = items: id: 1 datas: title: 'TITLE 1' title: 'TITLE 2' title: 'TITLE 3' id: 2 datas: title: 'TITLE 4' title: 'TITLE 5' ;assert;