itheima-tools-zm
Version:
提供了格式化时间、HTMLEscape相关功能
38 lines (33 loc) • 902 B
Markdown
## install
...
npm install itheima-tools-zm
...
## import
...js
const itheima = require('itheima-tools-zm')
...
## 格式化时间
...js
// 调用dateFormat对时间进行格式化
const dt = itheima.dateFormat(new Date())
// 结果 2022-04-02 23:59:03
console.log(dt)
...
## 转义html中的特殊字符
...js
// 带转换的HTML的字符串
const htmlStr = '<h1 title="ABC">这是h1标签<span>123 </span></h1>'
// 调用htmlEscape方法进行转换
const str = itheima.htmlEscape(htmlStr)
// 转换的结果 <h1 title="ABC">这是h1标签<span>123&nbsp;</span></h1>
console.log(str)
...
## 还原html中的特殊字符
...js
// 待还原html中的字符串
const unStr = itheima.htmlUnEscape(str)
// 输出结果 <h1 title="ABC">这是h1标签<span>123 </span></h1>
console.log(unStr)
...
## 开源协议
ISC