Package Exports
- shape-json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shape-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mirror a collection
Mirror a json by a scheme.
var shape = require('shape-json');
var input = {
pid: 1,
lastName: 'Stehle',
firstName: 'Andre'
};
var scheme = {
id: 'pid',
last_name: 'lastName',
};
console.log(shape.mirror(input, scheme));
/*
{
id: 1,
last_name: 'Stehle'
}
*/
var inputs = [{
pid: 1,
lastName: 'Stehle',
firstName: 'Andre'
},{
pid: 2,
lastName: 'lastname',
firstName: 'firstname'
}];
console.log(shape.mirror(inputs, scheme));
/*
[{
id: 1,
last_name: 'Stehle'
},{
id: 2,
last_name: 'lastname'
}]
*/Index an Array by a key.
var inputs = [{
id: 1,
last_name: 'Stehle'
},{
id: 2,
last_name: 'lastname'
}];
console.log(shape.indexBy(inputs, 'id'));
/*
{
1:{
id: 1,
last_name: 'Stehle'
},
2:{
id: 2,
last_name: 'lastname'
}
}
*/Chain previous operations.
var inputs = [{
pid: 1,
lastName: 'Stehle',
firstName: 'Andre'
},{
pid: 2,
lastName: 'lastname',
firstName: 'firstname'
}];
var result = shape.chain(inputs)
.mirror(scheme)
.indexBy('id')
.collection;
console.log(result);
/*
{
1:{
id: 1,
last_name: 'Stehle'
},
2:{
id: 2,
last_name: 'lastname'
}
}
*/