1.0.0 • Published 2 years ago

itheima-zqytools v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

安装

npm install itheima-zqytools

导入方式

const itheima = require('itheima-zqytools')

格式化时间

// 调用 dateFormat 对时间进行格式化
const date = itheima.dateFormat(new Date())
//输出结果  例如:2022-08-18 17:15:08
console.log(date);

转义 HTML 中的特殊字符

//定义了待转换的html字符串
const htmlstr = '<h1 title="abc">想这事<span>123&nbsp;</span></h1>'
//调用转换html字符串的 htmlEscape 方法
const str = itheima.htmlEscape(htmlstr)
//转换的结果 :'&lt;h1 title=&quot;abc&quot;&gt;想这事&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
console.log(str);

还原 html 中的特殊字符串

//待还原的html特殊字符串
const gtr = '&lt;h1 title=&quot;abc&quot;&gt;想这事&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
//调用  htmlUnEscape  方法进行还原
const str = itheima.htmlUnEscape(gtr)
//打印结果 : '<h1 title="abc">想这事<span>123&nbsp;</span></h1>'
console.log(str);

开源协议

ISC