安装
npm install itheima-tools-xwd
导入
const it = require('itheima-tools-xwd')
格式化时间
//调用 dateFormat 对时间进行格式化
const time = it.dateFormat(new Date());
//结果 2022-05-26 19:21:06
console.log(time)
转义 HTML中的特殊字符
//定义了待转换的字符串
const str = '<h1>我是<span>和h1</span>标签</h1>';
//调用 html 方法进行转换
let resu = it.html(str);
//转换结果 <h1>我是<span>和h1</span>标签</h1>
console.log(resu);
还原 HTML中的特殊字符
//定义了待还原的字符串
const unstr = '<h1>我是<span>和h1</span>标签</h1>'
let unresu = it.unhtml(unstr);
console.log(unresu)
开源协议
ISC