1.0.1 • Published 2 years ago

html-escape-tools v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

安装

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