安装
npm install itheima-tools-qz
导入
const itheima = require('./itheima-tools-qz');
格式化时间
// 调用 dateFormat 方法对时间进行格式化
const time = itheima.dateFormat(new Date());
// 打印的结果 2022-05-23 11:21:00
console.log(time);
转义 HTML 中的特殊字符
// 待转换的 HTML 字符串
const htmlStr = '<h1 class="dl">哈哈哈哈哈 <span> 哈哈哈 </span></h1>'
// 调用 htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlStr);
// 打印结果 ⁢h1 class="dl">哈哈哈哈哈 ⁢span> 哈哈哈&nbsp;⁢/span>⁢/h1>
console.log(str);
还原 HTML 中的特殊字符
// 调用 htmlUnEscape 方法还原字符串
const str2 = itheima.htmlUnEscape(str);
// 打印结果 <h1 class="dl">哈哈哈哈哈 <span> 哈哈哈 </span></h1>
console.log(str2);
开源协议
ISC