1.0.0 • Published 2 years ago

itheima-tools-zoulizhi75 v1.0.0

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

安装

npm install itheima-tools-zoulizhi75

导入

const itheima = require('itheima-tools-zoulizhi75')

格式化时间

//调用dateFormat方法格式化时间
const dtStr = itheima.dateFormat(new Date())
console.log(dtStr)
// 结果 2022-09-03 20:45:07

转义html中的特殊字符

//定义待转换的字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</sapn></h1>'
//调用htmlEscape方法进行转换
const str = itheima.htmlEscape(htmlStr)
console.log(str)
//结果 &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/sapn&gt;&lt;/h1&gt;

还原html中特殊字符的用法

// str是待还原的字符串
//调用htmlunEscape方法进行还原
const newstr = itheima.htmlunEscape(str)
console.log(newstr)
//结果 <h1 title="abc">这是h1标签<span>123&nbsp;</sapn></h1>

开源协议

ISC