etl
Version:
Collection of stream-based components that form an ETL pipeline
51 lines (39 loc) • 981 B
JavaScript
var Streamz = require('streamz'),
util = require('util');
function expand(convert) {
if (!(this instanceof Streamz))
return new expand(convert);
Streamz.call(this);
if (convert == 'uppercase')
this.convert = function(d) {
return String(d).toUpperCase();
};
else if (convert == 'lowercase')
this.convert = function(d) {
return String(d).toLowerCase();
};
else
this.convert = convert;
}
util.inherits(expand,Streamz);
expand.prototype.expand = function(d) {
for (var key in d) {
var oldKey = key;
if (typeof this.convert === 'function')
key = this.convert(key);
if (key) {
if (typeof d[key] === 'object')
d[key] = this.expand(d[oldKey]);
else
d[key] = d[oldKey];
if (oldKey !== key)
delete d[oldKey];
} else
delete d[oldKey];
}
return d;
};
expand.prototype._fn = function(d) {
return this.expand(Object.create(d));
};
module.exports = expand;