Escapes and unescapes the characters for HTML
- Escapes and unescapes the characters for HTML
- Tagged templates (Template literals) can also be used to escape only certain parts of the string.
Examples
import HtmlEscape from '@saekitominaga/string-escape-html';
HtmlEscape.escape('<span data-foo="hoge&hoge">text</span>'); // <span data-foo="hoge&hoge">text</span>
HtmlEscape.unescape('<span data-foo="hoge&hoge">text</span>'); // <span data-foo="hoge&hoge">text</span>
const span = '<span>text</span>';
HtmlEscape.template`<p>${span}</p>`; // <p><span>text<span></p>
/* Short method name */
import Html from '@saekitominaga/string-escape-html';
Html._('<span data-foo="hoge&hoge">text</span>');
Html.$('<span data-foo="hoge&hoge">text</span>');
const span = '<span>text</span>';
Html.__`<p>${span}</p>`;
Methods
static escape(input: string): string
- Escapes the characters in a string using character references
static _(input: string): string
- Alias of
escape()
static unescape(input: string): string
- Unescape characters for which character references are used
static $(input: string): string
- Alias of
unescape()
static template(input: TemplateStringsArray, ...placeholders: unknown[]): string
- Escapes for the placeholder in template literals
static __(input: TemplateStringsArray, ...placeholders: unknown[]): string
- Alias of
template()