unescapeHtml
EditDecodes the HTML entities produced by escapeHtml.
const entities: Record<string, string> = { "<": "<", ">": ">", """: '"', "'": "'", "'": "'", "&": "&",};
/** Decodes the HTML entities produced by escapeHtml. */export const unescapeHtml = (value: string): string => { return value.replace(/&(lt|gt|quot|#39|#x27|amp);/gi, (entity) => entities[entity.toLocaleLowerCase()] ?? entity);};Download
Section titled “Download”wget -O src/lib/unescapeHtml.ts https://raw.githubusercontent.com/jrTilak/lazykit/HEAD/registry/functions/unescapeHtml.tstemp_dir="$(mktemp -d)" && bunx degit jrTilak/lazykit/registry/functions "$temp_dir" && mv "$temp_dir/unescapeHtml.ts" src/lib/unescapeHtml.ts && rm -r "$temp_dir"Examples
Section titled “Examples”import { unescapeHtml } from "./unescapeHtml";
const text = unescapeHtml("<strong>Hello</strong>");value(string) — Text containing supported entities.- Decodes one layer of
lt,gt,quot,amp,#39, and#x27entities.