1.0.1 • Published 8 months ago
purple-utils v1.0.1
安装方式
npm install purple-utils
导入
const purpleUtils = require('./purple-utils');
格式化时间
const dt = new Date();
const str = purpleUtils.dateFormat(dt);
console.log(str); // 输出 2023-04-02 02:34:09
转义 HTML 中的特殊字符
const htmlStr = '<h1 style="color: red;">你好!© <span>小黄</span></h1>'
const htmlEscape = purpleUtils.htmlEscape(htmlStr);
// 输出 <h1 style="color: red;">你好!&copy <span>小黄</span></h1>
console.log(htmlEscape);
还原 HTML 中的特殊字符串
const htmlUnEscape = purpleUtils.htmlUnEscape(htmlEscape);
// 输出 <h1 style="color: red;">你好!© <span>小黄</span></h1>
console.log(htmlUnEscape)
开源协议
ISC