2.0.2 • Published 4 months ago

@saekitominaga/string-escape-html v2.0.2

Weekly downloads
45
License
MIT
Repository
github
Last release
4 months 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 '@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

2.0.2

4 months ago

1.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago