@gurgunday/html v7.1.0
Replace your template engine with fast JavaScript by leveraging the power of tagged templates.
Inspired by html-template-tag.
Installation
npm i @gurgunday/html
API Reference
The main export of the package is the html
function that can be used to tag template literals and escape their expressions. To bypass escaping an expression, prefix it with !
.
Node.js users also have access to the includeFile
function that reads and outputs the content of a file while caching it in memory for future use.
Usage
import { html } from "@gurgunday/html";
const username = '<img src="https://example.com/hacker.png">';
const greeting = html`<h1>Hello, ${username}!</h1>`;
console.log(greeting);
// Output: <h1>Hello, <img src="https://example.com/hacker.png"></h1>
const img = '<img src="https://example.com/safe.png">';
const container = html`<div>!${img}</div>`;
console.log(container);
// Output: <div><img src="https://example.com/safe.png"></div>
The includeFile
function returns the content of a file. Again, remember that it also caches the result, so any subsequent modifications to the same file won't be reflected until the app is restarted:
import { includeFile } from "@gurgunday/html/includeFile.js";
const logo = includeFile("static/logo.svg");
console.log(logo);
// Output: content of "static/logo.svg"
4 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
6 months ago
6 months ago
7 months ago
6 months ago
6 months ago
6 months ago
7 months ago
10 months ago
7 months ago
10 months ago
5 months ago
5 months ago
10 months ago
5 months ago
10 months ago
6 months ago
8 months ago
6 months ago
9 months ago
6 months ago
10 months ago
8 months ago
9 months ago
9 months ago
7 months ago
7 months ago
11 months ago
11 months ago
11 months ago