1.0.0 • Published 2 years ago

node-xxl-tools v1.0.0

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

安装

npm i node-learn-tools

导入

const nodeLearnTools = require('node-learn-tools');

格式化时间

//调用 dateformDate 对时间进行格式化
let data = new Date() 
// 结果 2022-10-20 13:10:47
console.log(nodeLearnTools.dateformDate(data))

转义 html 字符串

//调用 htmlEscape 对html 进行转义
let htmlStr = '<h2 style="color:red;">这是一段文本&nbsp;<span>你好</span></h2>'
// 结果 &lt;h2 style=&quot;color:red;&quot;&gt;这是一段文本&amp;nbsp;&lt;span&gt;你好&lt;/span&gt;&lt;/h2&gt
console.log(nodeLearnTools.htmlEscape(htmlStr))

还原 html

//调用 htmlEscape htmlUnEscape 进行转义
let str = '&lt;h2 style=&quot;color:red;&quot;&gt;这是一段文本&amp;nbsp;&lt;span&gt;你好&lt;/span&gt;&lt;/h2&gt;'
// 结果<h2 style="color:red;">这是一段文本&nbsp;<span>你好</span></h2>
console.log(nodeLearnTools.htmlUnEscape(str))

开源协议

ISC