UNPKG

huangluoxuan-tools

Version:

提供了时间格式化、HTMLEscape相关的功能

38 lines (31 loc) 712 B
## 安装 ``` npm install huangluoxuan-tools ``` ## 导入 ```js const huangluoxuan = require('huangluoxuan-tools') ``` ## 格式时间 ```js //调用dateFormat const str = huangluoxuan.dateFormat(new Date()) //结果 2020-04-04 17:20:32 console.log(str) ``` ## 转义HTML中特殊的字符 ```js //调用htmlEscape进行转换 const htmlStr = '<h1 title="abc">测试&nbsp;</h1>' //结果 &lt;h1 title=&quot;abc&quot;&gt;测试&amp;nbsp;&lt;/h1&gt; const str1 = huangluoxuan.htmlEscape(htmlStr) ``` ## 还原HTML中特殊的字符 ```js //待还原的HTML字符串 const str2 = huangluoxuan.htmlUnEscape(str1) //输出结果 <h1 title="abc">测试&nbsp;</h1> console.log(str2) ``` ## 开源协议 ISC