UNPKG

lasso-require

Version:

Lasso.js plugin to support Node.js style module require in the browser

29 lines (24 loc) 750 B
'use strict'; var stream = require('stream'); class MyTransform extends stream.Transform { constructor(file, opts) { super(); this.file = file; this.data = ''; this.replacement = opts.replacement; } _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) { var replacement = this.replacement; this.push(this.data.replace(/hello/g, replacement) + '|filename=' + this.file); callback(); } } module.exports = function(file, opts) { return new MyTransform(file, opts); };