querymap
v1.0.3
Published
use query string to map one object or array into another object or array
Downloads
7
Readme
use query string to map one object or array into another object or array
useage:
import { queryMap } from 'querymap';
let source = [{ a: 1, b: { c: { d: 2 } } }];
let dest = queryMap(source, 'a as m, b.c.d as n, "string" as l');
console.log(dest); // { m: 1, n: 2, l: 'string' } ]
source = { a: [1, 2, 3] };
dest = queryMap(source, 'a as m', function(item) {
item.m = item.m.map((i) => i * 2);
return item;
});
console.log(dest); // { m: [ 2, 4, 6 ] }
source = [{ a: 1, b: { c: { d: 2 } } }];
dest = queryMap(source, 'a as m, b.c.d, "string" as l');
console.log(dest); // [ { m: 1, d: 2, l: 'string' } ]
source = [{ a: 1, b: { c: { d: 2 } }, k: 1, q: 'good' }];
dest = queryMap(source, 'a as m, b.c.d, "string" as l, ...'); // ... means rest
console.log(dest); // [ { m: 1, d: 2, l: 'string', k: 1, q: 'good' } ]