
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
@byte-this/email-templator
Advanced tools
Typescript API to facilitate email markup generation and help deal with bad email clients.
For details and info on how to use: https://bytethisstore.com/articles/pg/email-templating
An api which makes email markup generation a bit easier to deal with. Creating email html is a but cumbersome, as email clients haved mixed support for certain styling attributes, especially more modern ones.
This email-templator:
Library with typescript definitions available as npm package.
npm install @byte-this/email-templator
You will need two or three of the following:
The styles and interpolation values will be denoted as {{ }}, similar to Angular interpolation (note that this is not an Angular library and does not support directives, templates, etc).
The following is an example:
/**
* Here is some basic markup to be sent as a greeting to a new user.
*
* Notice that we have some interpolation going on:
* --> #main-header, personFullName, .excited-greeting, #websiteUrl
*/
const markup = `
<h1 {{#main-header}}>Hello, {{personFullName}}</h1>
<p {{.excited-greeting}}>
Thanks for joining our system!
</p>
<p>
We look forward to seeing you on our website at {{websiteUrl}}
</p>
<p {{.excited-greeting}}>
See you soon!
</p>
`;
/**
* This is a key value representation of the style names vs rules
* By convention, it looks very similar to an actual css style definition
*/
const styles = {
'#main-header': `
color: purple;
font-weight: bold;
`,
'.excited-greeting': `
width: 700px;
border-color: 1px sold black;
`
};
//a simple dictionary of values to insert
const values = {
personFullName: "Brandon Dixon",
websiteUrl: "www.bytethisstore.com"
};
//Now let's create the full body template
const emailTemplator = new EmailTemplator();
const generatedMarkup = emailTemplator.generateMarkup(markup, styles, values);
The response will look something like this:
<h1 style="color: purple; font-weight: bold;" >Hello, Brandon Dixon</h1>
<p style="width: 700px; border-color: 1px sold black;" width="700" >
Thanks for joining our system!
</p>
<p>
We look forward to seeing you on our website at www.bytethisstore.com
</p>
<p style="width: 700px; border-color: 1px sold black;" width="700" >
See you soon!
</p>
In the javascript example above, I've created a styles object where the key/value pairs look very similar to how css is normally declared. I've also added "." and "#" in front of what would normally be a class vs an identifier. That is not enforced by the API, but I consider it to be a useful convention and recommend anyone who uses this library to follow that convention. The values are a simple key/value pair representing values which need to be interpolated.
The output contains all interpolations of values, plus styles wrapped in a "style=" tag. Width and height are also extracted into their own properties when they are represented in terms of "px".
When using the style interpolation, any element which will have this style interpolation cannot have any additional "style" tags declared in the markup. It can have other class specifications / styles which are declared in a separate part of the html template. A single html element can only have one style interpolation for a similar reason.
This library does not offer any HTML sanitation. If you are inserting any dynamic markup / data which has not been cleansed, be sure to pass the data through some library before passing it in here.
FAQs
Typescript API to facilitate email markup generation and help deal with bad email clients.
We found that @byte-this/email-templator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Company News
Socket is bringing best-in-class reachability analysis into the platform — cutting false positives, accelerating triage, and cementing our place as the leader in software supply chain security.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.