1.0.0 • Published 3 years ago
xiaoxu-tools v1.0.0
安装
npm i xiaoxu-tools
导入
cosnt xiaoxu=require('xiaoxu-tools')
格式化时间
//调用dateFormat 对时间进行格式化
const date=xiaoxu.dateFormat(new Date())
// 结果 2021-11-16 16:54:32
console.log(date)
转义HTML中的特殊字符
// 待转化的 HTML字符串
const htmlStr = '<h1 style="color:red">这是h1<span title="用户喜欢耍流氓">123 </span></h1>'
// 调用 htmlEscape 方法进行转换
let newHTML = xiaoxu.htmlEscape(htmlStr)
// 转化结果 <h1 style="color:red">这是h1<span title="用户喜欢耍流氓">123&nbsp;</span></h1>
console.log(newHTML)
还原 HTML中的特殊字符
//带还原的 HTML字符串 <h1 style="color:red">这是h1<span title="用户喜欢耍流氓">123&nbsp;</span></h1>
const newHTML=xiaoxu.htmlUnEscape(html)
// 输出结果 <h1 style="color:red">这是h1<span title="用户喜欢耍流氓">123 </span></h1>
console.log(newHTML)
开源协议
ISC
1.0.0
3 years ago