Skip to main content
This release is a pre-release — the latest non-prerelease version of @thai/html is 0.0.5. Jump to this version

@thai/html@0.1.0-alpha.0
Built and signed on GitHub Actions

Safely generate HTML strings

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 months ago (0.1.0-alpha.0)

The @thai/html package provides the html tagged template function that can be used to safely generate HTML code.

Usage

import { html, renderHtml } from "@thai/html";

// Strings are escaped
console.log(renderHtml("<>")); // "&lt;&gt;"

// 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>&lt;&gt;</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}`)); // ""
Built and signed on
GitHub Actions
View transparency log

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";