html-escape-tools

1.0.1 • Public • Published

安装

npm i html-escape-tools

导入

const escapeTools = require('html-escape-tools');

转义 HTML 中的特殊字符

// 待转换的 HTML 字符串
const str = '<h1 title="123">123&nbsp;</h1>';
// 调用 htmlEscape 方法进行转换
const newStr = escapeTools.htmlEscape(str);
// 转换的结果 &lt;h1 title=&quot;123&quot;&gt;123&amp;nbsp;&lt;/h1&gt;
console.log(newStr)

还原 HTML 中的特殊字符

// 待转换的 HTML 字符串
const str = '&lt;h1 title=&quot;123&quot;&gt;123&amp;nbsp;&lt;/h1&gt';
// 调用 htmlUnEscape 方法进行转换
const newStr = escapeTools.htmlUnEscape(str);
// 输出的结果 <h1 title="123">123&nbsp;</h1>
console.log(newStr);

开源协议

ISC

Readme

Keywords

Package Sidebar

Install

npm i html-escape-tools

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

2.39 kB

Total Files

5

Last publish

Collaborators

  • xd_pig