1.0.1 • Published 2 years ago
lyk-tools v1.0.1
安装
npm install lyk-tools
导入
const lyk = require("lyk-tools");
格式化时间
//调用 formatDate() 方法格式化时间
const date = lyk.formatDate(new Date());
//输出结果 2022-05-24 17:01:17
console.log(date);
转义 HTML 特殊字符
// 待转换的 HTML 的字符串
const htmlStr = '<h1 style="color:red">这是h1标签<span>123 </span></h1>';
//调用 htmlEscape() 方法转义 HTML 特殊字符
const newHtmlStr = lyk.htmlEscape(str);
// 输出结果 <h1 style="color:red">这是h1标签<span>123&nbsp;</span></h1>
console.log(newHtmlStr);
还原 HTML 特殊字符
// 调用 htmlUnEscape() 方法还原 HTML 特殊字符
const unescapeHtmlStr = lyk.htmlUnEscape(newHtmlStr);
// 输出结果 <h1 style="color:red">这是h1标签<span>123 </span></h1>
console.log(unescapeHtmlStr);
开源协议
ISC