Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
html-template-tag
Advanced tools
ES6 Tagged Template for compiling HTML template strings.
This package is distributed via npm:
npm install html-template-tag
At its core, this module just performs simple ES6 string interpolation.
var html = require("html-template-tag");
// - or - import html from "html-template-tag";
var name = `Antonio`;
var string = html`Hello, ${name}!`;
// "Hello, Antonio!"
Nevertheless, it escapes HTML special characters without refraining its use in loops!
var html = require("html-template-tag");
// - or - import html from "html-template-tag";
var names = ["Antonio", "Megan", "/><script>alert('xss')</script>"];
var string = html`
<ul>
${names.map((name) => html` <li>Hello, ${name}!</li> `)}
</ul>
`;
// "<ul><li>Hello, Antonio!</li><li>Hello, Megan!</li><li>Hello, /><script>alert('xss')</script>!</li></ul>"
You can use double dollar signs in interpolation to mark the value as safe (which means that this variable will not be escaped).
var name = `<strong>Antonio</strong>`;
var string = html`Hello, $${name}!`;
// "Hello, <strong>Antonio</strong>!"
This small module can also be used to pre-compile HTML templates:
var html = require("html-template-tag");
// - or - import html from "html-template-tag";
var data = {
count: 2,
names: ["Antonio", "Megan"],
};
var template = ({ names }) => html`
<ul>
${names.map((name) => html` <li>Hello, ${name}!</li> `)}
</ul>
`;
var string = template(data);
/*
"
<ul>
<li>Hello, Antonio!</li>
<li>Hello, Megan!</li>
</ul>
"
*/
NB: The formating of the string literal is kept.
To avoid XSS attacks, this package removes all interpolation instide URI attributes (more info). This package also ensures that interpolations inside attributes are properly escaped.
MIT
The code for this module has been heavily inspired on Axel Rauschmayer's post on HTML templating with ES6 template strings and Stefan Bieschewski's comment.
FAQs
ES6 Tagged Template for compiling HTML template strings.
We found that html-template-tag demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.