This package has been deprecated

Author message:

This package has been moved to @w0s/html-escape

@saekitominaga/string-escape-html
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Escapes and unescapes the characters for HTML

npm version test status

  • 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>'); // &lt;span data-foo=&quot;hoge&amp;hoge&quot;&gttext&lt;/span&gt;
HtmlEscape.unescape('&lt;span data-foo=&quot;hoge&amp;hoge&quot;&gttext&lt;/span&gt;'); // <span data-foo="hoge&hoge">text</span>

const span = '<span>text</span>';
HtmlEscape.template`<p>${span}</p>`; // <p>&lt;span&gt;text&lt;span&gt;</p>
/* Short method name */
import Html from '@saekitominaga/string-escape-html';

Html._('<span data-foo="hoge&hoge">text</span>');
Html.$('&lt;span data-foo=&quot;hoge&amp;hoge&quot;&gttext&lt;/span&gt;');

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()

Readme

Keywords

Package Sidebar

Install

npm i @saekitominaga/string-escape-html

Weekly Downloads

3

Version

2.0.2

License

MIT

Unpacked Size

42.2 kB

Total Files

7

Last publish

Collaborators

  • saekitominaga