1.0.0 • Published 4 years ago
kwj-tools v1.0.0
安装
npm install kwj-tools
导入
const kwj = require("kwj-tools");
格式化时间
// 调用 dateFormat函数对时间进行格式化
const date = kwj.dateFormat(new Date());
console.log(date); // 输出 2021-06-11 20:00:01
转义 HTML 中的特殊字符
// 声明一个 html 字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123 </span></h1>';
// 使用 HTMLEscape函数对 html 进行转义
const str = kwj.HTMLEscape(htmlStr);
console.log(str);
// 输出 <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>
还原 HTML 中的特殊字符
// 声明一个待还原的 HTML 字符串
const str =
"<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>";
// 调用 HTMLUnEscape 函数
const htmlStr = kwj.HTMLUnEscape(str);
console.log(htmlStr1);
// 输出还原后的结果 <h1 title="abc">这是h1标签<span>123 </span></h1>
开源协议
ISC
1.0.0
4 years ago