lasso-require
Version:
Lasso.js plugin to support Node.js style module require in the browser
27 lines (22 loc) • 621 B
JavaScript
;
var stream = require('stream');
class MyTransform extends stream.Transform {
constructor(file) {
super();
this.file = file;
this.data = '';
}
_transform(buf, enc, callback) {
// Collect all of the data as it is streamed in and just concatenate to a our data string
// but don't actually stream out any data yet
this.data += buf;
callback();
}
_flush(callback) {
this.push(this.data + '|my-transform|file=' + this.file);
callback();
}
}
module.exports = function(file) {
return new MyTransform(file);
};