Skip to main content
Module

std/html/entities.ts>escape

Deno standard library
Go to Latest
function escape
import { escape } from "https://deno.land/std@0.191.0/html/entities.ts";

Escapes text for safe interpolation into HTML text content and quoted attributes

Examples

Example 1

import { escape } from "https://deno.land/std@0.191.0/html/entities.ts";
import { assertEquals } from "https://deno.land/std@0.191.0/testing/asserts.ts";

assertEquals(escape("<>'&AA"), "&lt;&gt;&#39;&amp;AA");

// characters that don't need to be escaped will be left alone,
// even if named HTML entities exist for them
assertEquals(escape("þð"), "þð");

Parameters

str: string