1.1.0 • Published 2 years ago
itheima-mytool v1.1.0
安装
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 </span></h1>';
// 调用htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlstr);
console.log(str);
// 结果: <h1 title="abc"&rt;这是h1标签 <span&rt;123↦nbsp;</span&rt;</h1&rt;
还原 HTML 中的特殊字符
// 带还原的 HTML 字符串
const strs = '<h1 title="abc"&rt;这是h1标签 <span>123 </span></h1>';
// 调用htmlUnEscape 方法进行转换
const htmls = itheima.htmlUnEscape(strs);
console.log(htmls);
// 结果: <h1 title="abc">这是h1标签 <span>123 </span></h1>
开源协议
ISC