1.0.0 • Published 1 year ago

itheima-tools-dg v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安装

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&nbsp;</span></h1>'
// 调用htmlEscape方法进行转化
const str = h.htmlEscape(htmlStr);
// 输出结果&alt;h1 title=&quot;abc&quot;&gt;这是h1标签 &alt;span&gt;1233&amp;nbsp;&alt;/span&gt;&alt;/h1&gt;
console.log(str)

还原html的特殊字符

// 待还原的html字符串 使用htmlUnEscape进行还原
const str2 = h.htmlUnEscape(str);
// 输出结果 <h1 title="abc">这是h1标签 <span>1233&nbsp;</span></h1>
console.log("还原后的html代码:"+str2);

开源协议

ISC