To build:
npm run build
Build files are added to the dist/
directory.
To publish this package, increment version number in package.json, then run:
npm publish
To install this package:
npm install @theshed/template-printer --save
import { Injector } from "template-printer";
// initialize variable types with opening/closing tags
let myInjector = new Injector(
{
foo: {
open: "{{",
close: "}}",
transform: function(value, cb){ // optional transformation callback
// transform value
cb(value);
}
}
/* ... more variable types ... */
}
);
// set or override handler for variable type foo
myInjector.setHandler("foo", function(value, cb){
// transform value
cb(value.toUpperCase());
})
let text = "tacos are so foo {{foo}}";
// inject transformed data into text
myInjector
.InjectVariables(text, {
foo: "bar"
})
.then(output => {
console.log(output); // <- "tacos are so foo BAR"
});
To print text/html content:
import { PrintToIframe } from "template-printer";
// spawns print dialg with specified dimensions in inches (4in x 6in)
PrintToIframe("tacos are so foo bar", 4, 6);
Altogether:
import { Injector, PrintToIframe } from "template-printer";
let myInjector = new Injector();
// "text" is one of the default variable types
// here I'm overriding the existing transformation function
myInjector.setHandler("text", function(value, cb){
cb(value.toUpperCase());
});
let text = "tacos are so foo {{foo}}";
myInjector
.InjectVariables(text, {
foo: "bar"
})
.then(output => {
// print injected/transformed content to a 4in x 6in page.
PrintToIframe(output, 4, 6);
});