1.0.1 • Published 2 years ago

test-hc v1.0.1

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

安装

npm install test-hc

导入

const test = require('test-hc')

格式化时间

// 调用 dataFormate 对时间进行格式化
const dataTime = test.dataFormat(new Date())
// 结果 2022-01-25 14:27:21
console.log(dataTime)

转义 html 中的特殊字符

// 调用 htmlEscape 转义字符
const htmlStr = test.htmlEscape(
  '<h1 title="abc">这是 h1 标签<span>123&nbsp;</span></h1>'
)
// 结果 &lt;h1 title=&quot;abc&quot;&gt;这是 h1 标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(htmlStr)

还原 html 中的特殊字符

//调用 htmlUnEscape 还原字符
const Str = test.htmlUnEscape(htmlStr)
//结果 <h1 title="abc">这是 h1 标签<span>123&nbsp;nbsp;</span></h1>
console.log(Str)