object-convert
Convert an object from one schema to another.
Installation
$ npm install --save object-convert
Usage
var converter = require('object-convert'),
type = converter.type;
converter().define({
user: {
fullName: type(String, 'name'),
bornOn: type(Date, 'birthDate'),
likesCats: type(Boolean, 'interestingFacts.likesDogs'),
hasPets: type(Boolean, 'interestingFacts.petNames', function(value) {
return !!value.length;
})
}
}).convert({
name: 'Matthew Slipper',
birthDate: new Date(),
interestingFacts: {
likesDogs: true,
petNames: [ 'Speedy' ]
}
});
License
MIT © Matthew Slipper