This release is 1 version behind 0.0.5 — the latest version of @thai/html. Jump to latest
Safely generate HTML strings
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
JSR Score
100%
Published
7 months ago (0.0.4)
The @thai/html
package provides the html
tagged template function
that can be used to safely generate HTML code.
▶Example 1
Example 1
import { html, renderHtml } from "@thai/html"; // Strings are escaped console.log(renderHtml('<>')); // "<>" // Numbers and booleans are converted to strings console.log(renderHtml(42)); // "42" console.log(renderHtml(true)); // "true" // HTML code can be generated using the `html` tagged template function console.log(renderHtml(html`<b>${'<>'}</b>`)); // "<b><></b>" // Arrays are concatenated console.log(renderHtml(['one', 'two', 'three'])); // "onetwothree" // `null` and `undefined` are converted to an empty string console.log(renderHtml(html`${null}`)); // ""
Add Package
deno add jsr:@thai/html
Import symbol
import * as mod from "@thai/html";
---- OR ----
Import directly with a jsr specifier
import * as mod from "jsr:@thai/html";
Add Package
npx jsr add @thai/html
Import symbol
import * as mod from "@thai/html";
Add Package
yarn dlx jsr add @thai/html
Import symbol
import * as mod from "@thai/html";
Add Package
pnpm dlx jsr add @thai/html
Import symbol
import * as mod from "@thai/html";
Add Package
bunx jsr add @thai/html
Import symbol
import * as mod from "@thai/html";