README
bumblebee
Object transformation tool inspired on mongoose models. The basic idea is to contruct a result object, form a model and a reference object (and also you can pass an object as base).
Getting Started
Install the module with: npm install bumblebee
var bumblebee = require('bumblebee-object-transformation');
bumblebee(initialObject, referenceObject, model, function(err, result){
console.log(result);
//Your code....
});
Documentation
Basically you should use as model the final object, and field by field you can speficy:
__format
: (to specify the default format)__default
: (if bumblebee dont find the field you can specify a default field)__composer
: (to make some operations predefined)__scheema
: (to compose the scheema of this field)__originField
: (to specify the orifinal field inside the object, remeber that any scheema that you define inside the composer use their own element or subobject as reference)__clean
: (to use over the object selected my object cleaner, that removes innecesarry arrays with lenght 0, really usefull when you convert from xml to js.)
For now the operations are:
- RegEx : to find inside the object a fields and put in an array.
- everyElement : to loop over the elements of an array and make the transformations
- everyElementToArray : to loop over the elements of an array and create an object, you need to specify the key of the every element (__key)
Remember that this module is underconstruction, if you have some needs try to follow the essential structure of the application, and i try to merge all request. Usully i use this module, so im adapting frecuently, and sometimes wont be really well optimized, all suggestions are welcome.
Thanks!
Examples
(From 0.3.X Examples)
initialObject = {};
var referenceObject = {
'title' : 'title',
'text': 'hey im a text',
'position' : [ 41.3901566, 2.1355214 ],
'you' : {
'video' : {
'active': true,
'times': 4,
'information':{
'duration': 10,
'format': 'min'
}
}
},
'youtube':{
'expiration': 'DATE',
'expirationTimezone': 'GMT+1'
},
'buyNowConfig': {
'price': 100
},
'product':{
'images':[
{ url: 'http://lkjljklkj/123'},
{ url: 'http://lkjljklkj/456'},
{ url: 'http://lkjljklkj/678'},
{ url: 'http://lkjljklkj/999'},
]
},
providers:[{
'