1.0.0 • Published 1 year ago
itheima-tools-dg v1.0.0
安装
npm install itheima-tools-dg
导入
const h = require("itheima-tools-dg")
格式化时间
// 调用dataFormat对时间进行格式化
const currentDate = h.dataFormat(new Date())
// 输出结果 2023-03-02 14:23:24
console.log(currentDate)
转义html中的特殊字符
//待转化的html字符串
const htmlStr = '<h1 title="abc">这是h1标签 <span>1233 </span></h1>'
// 调用htmlEscape方法进行转化
const str = h.htmlEscape(htmlStr);
// 输出结果&alt;h1 title="abc">这是h1标签 &alt;span>1233&nbsp;&alt;/span>&alt;/h1>
console.log(str)
还原html的特殊字符
// 待还原的html字符串 使用htmlUnEscape进行还原
const str2 = h.htmlUnEscape(str);
// 输出结果 <h1 title="abc">这是h1标签 <span>1233 </span></h1>
console.log("还原后的html代码:"+str2);
开源协议
ISC
1.0.0
1 year ago