@signalk/streams
Version:
Utilities for handling streams of Signal K data
21 lines (20 loc) • 594 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const stream_1 = require("stream");
class Replacer extends stream_1.Transform {
regexp;
template;
constructor(options) {
super({ objectMode: true });
this.regexp = new RegExp(options.regexp, 'gu');
this.template = options.template;
}
_transform(chunk, encoding, done) {
const result = chunk.toString().replace(this.regexp, this.template);
if (result.length > 0) {
this.push(result);
}
done();
}
}
exports.default = Replacer;