1.0.1 • Published 2 years ago
html-escape-tools v1.0.1
安装
npm i html-escape-tools
导入
const escapeTools = require('html-escape-tools');
转义 HTML 中的特殊字符
// 待转换的 HTML 字符串
const str = '<h1 title="123">123 </h1>';
// 调用 htmlEscape 方法进行转换
const newStr = escapeTools.htmlEscape(str);
// 转换的结果 <h1 title="123">123&nbsp;</h1>
console.log(newStr)
还原 HTML 中的特殊字符
// 待转换的 HTML 字符串
const str = '<h1 title="123">123&nbsp;</h1>';
// 调用 htmlUnEscape 方法进行转换
const newStr = escapeTools.htmlUnEscape(str);
// 输出的结果 <h1 title="123">123 </h1>
console.log(newStr);
开源协议
ISC