1.0.0 • Published 4 years ago

itzhangyi-tools v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

安装

npm i itzhangyi-tools

导入

const itzhang = require("./itzhangyi-tools");

格式化时间

// 调用 dateFormat 对时间进行格式化
const dt = itzhang.dateFormat(new Date());
// 结果  2021-01-16 20:00:00
console.log(dt);

转义 HTML 中的特殊字符

// 待转换的 HTML 字符串
const htmlStr = '<h4 title="小张fighting">这是h4标签<span>123&nbsp;</span></h4>';
// 调用 htmlEscape 方法进行转换
const result = itzhang.htmlEscape(htmlStr);
// 转换的结果 &lt;h4 title=&quot;小张fighting&quot;&gt;这是h4标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;
console.log(result);

还原 HTML 中的特殊字符

// 待还原的 HTML 字符串
const r2 = itzhang.htmlUnEscape(result);
// 输出的结果 <h4 title="小张fighting">这是h4标签<span>123&nbsp;</span></h4>
console.log(r2);

开源协议

ISC