1.0.1 • Published 2 years ago

liudongyu-tools v1.0.1

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

安装

npm install liudongyu-tools

导入

const tools = require('liudongyu-tools')

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = tools.dateFormat(new Date())

// 打印时间: 2022-10-03 22:12:33
console.log(dtStr)

转义 HTML 中的特殊字符

// 转义 HTML 
const htmlStr = '<h1 title = "abc">这是h1标签<span>123&nbsp;</span></h1>'
const str = tools.htmlEscape(htmlStr)
// 输出结果:&lt;h1 title = &quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原 HTML 中的特殊字符

// 还原HTML 
const Str = '&lt;h1 title = &quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
const htmlstr = tools.htmlUnEscape(str)

// 输出结果:<h1 title = "abc">这是h1标签<span>123&nbsp;</span></h1>
console.log(htmlstr)

开源协议

ISC