0.2.0 • Published 9 years ago
node-transmute v0.2.0
Transmute
A simple library to transmute data into new forms.
- Transmutes single items.
- Transmutes a collection of items.
Installing transmute
The package is available at npm and can be installed by doing:
npm install node-transmute
How to use transmute
First load the transmute module and define a transmuter function.
var transmute = require('node-transmute');
function personTransmuter(person, callback) {
var transmuted = {
id: person.id,
name: person.firstname + ' ' + person.lastname,
location: {
city: person.city
}
};
callback(null, transmuted);
}
Transmuting a single item
var person = {
id: 1,
firstname: 'John',
lastname: 'Doe',
city: 'New York'
};
transmute.one(person, personTransmuter, function (err, result) {
console.log(result);
});
Transmuting a collection of items
var persons = [
{
id: 1,
firstname: 'John',
lastname: 'Doe',
city: 'New York'
},
{
id: 2,
firstname: 'Jane',
lastname: 'Doe',
city: 'Los Angeles'
}
];
transmute.collection(persons, personTransmuter, function (err, result) {
console.log(result);
});