3.0.0 • Published 2 years ago

@w0s/html-escape v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 '@w0s/html-escape';

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 '@w0s/html-escape';

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

3.0.0

2 years ago