UNPKG

dkc-tools

Version:

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

38 lines (33 loc) 837 B
## 安装 ``` npm install dkc-tools ``` ## 导入 ```js const dkc = require('dkc-tools') ``` ## 格式化时间 ```js // 调用 dateFormat 对时间进行格式化 const te = time.dataFormat(new Date()) //输出结果 2022-04-01 10:37:06 console.log(te) ``` ## 转义 HTML 特殊字符 ```js // 定义了待转义的 HTML 字符串 const str = "<h1 title='zbc'>hell! <span>小黄</span></h1>" // 调用 htmlEscape方法进行转换 const tr = time.htmlEscape(str) // 转换的结果为 &lt;h1 title='zbc'&gt;hell! &lt;span&gt;小黄&lt;/span&gt;&lt;/h1&gt; console.log(tr) ``` ## 还原 HTML 中的特殊字符 ```js // 待还原的 HTML 字符串 const t = time.htmlUnEscape(tr) // 转换的结果为 <h1 title='zbc'>hell! <span>小黄</span></h1> console.log(t) ``` ## 开源协议 ISC