1.1.0 • Published 2 years ago

itheima-mytool v1.1.0

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

安装

npm i 2itheima-mytool

导入

const itheima = require('2itheima-mytool');

格式化时间

// 调用dateFormat 对时间格式化
const dt = itheima.dateFormat(new Date());
console.log(dt);
// 结果: 2022-10-18 21:49:11

转义 HTML 中的特殊字符

// 带转换的 HTML 字符串
const htmlstr = '<h1 title="abc">这是h1标签 <span>123&nbsp;</span></h1>';
// 调用htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlstr);
console.log(str);
// 结果: &lt;h1 title=&quot;abc&quot;&rt;这是h1标签 &lt;span&rt;123&map;nbsp;&lt;/span&rt;&lt;/h1&rt;

还原 HTML 中的特殊字符

// 带还原的 HTML 字符串
const strs = '&lt;h1 title=&quot;abc"&rt;这是h1标签 <span>123&nbsp;</span></h1>';
// 调用htmlUnEscape 方法进行转换
const htmls = itheima.htmlUnEscape(strs);
console.log(htmls);
// 结果: <h1 title="abc">这是h1标签 <span>123&nbsp;</span></h1>

开源协议

ISC