1.0.1 • Published 3 years ago

bqfj-tools v1.0.1

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

安装

npm install bqfj-tools

导入

const bqfj = require('bqfj-tools')

格式化时间

// 调用dateFormat 对时间进行格式化
const dateStr = bqfj.dateFormat(new Date());
// 结果: 2021-07-05 10:40:01
console.log(dateStr);

转义HTML 中的特殊字符

// 待转换的 HTML 字符串, 调用 htmlEscape 方法进行转换
const htmlStr = bqfj.htmlEscape('<h1 style="font-size:12px">哈哈</h1>')
// 输出结果: &lt;h1 style=&quot;font-size:12px&quot;&gt;哈哈&lt;/h1&gt;
console.log(htmlStr);

还原 HTML 中的特殊字符

// 待还原的 HTML 字符串 &lt;h1 style=&quot;font-size:12px&quot;&gt;哈哈&lt;/h1&gt;
const htmlStr1 = bqfj.htmlUnEscape(htmlStr);
// 输出结果: <h1 style="font-size:12px">哈哈</h1>
console.log(htmlStr1);

开源协议

ISC