html-transformer
v1.1.2
Published
HTML streaming transformer
Downloads
6
Readme
html-transformer
HTML transformer
Example
import Transformer from "html-transformer";
let env = {};
/**
set env
*/
const transformer = new Transformer();
transformer.onText(/{{[^}]+}}/, (_, matched) => {
return env[matched[1]];
})
.onTag("*", "placeholder", /{{[^}]+}}/, (_, matched) => {
return env[matched[1]];
})
.onBeforeClosingTag("body", () => {
return "<script src=\"inject_some_js.js\"></script>";
}).pipe(htmlOutput);
htmlInput.pipe(transformer);