1.0.1 • Published 8 months ago

purple-utils v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

安装方式

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;">你好!&copy <span>小黄</span></h1>'
const htmlEscape = purpleUtils.htmlEscape(htmlStr);
// 输出 &lt;h1 style=&quot;color: red;&quot;&gt;你好!&amp;copy &lt;span&gt;小黄&lt;/span&gt;&lt;/h1&gt;
console.log(htmlEscape);

还原 HTML 中的特殊字符串

const htmlUnEscape = purpleUtils.htmlUnEscape(htmlEscape);
// 输出 <h1 style="color: red;">你好!&copy <span>小黄</span></h1>
console.log(htmlUnEscape)

开源协议

ISC

1.0.1

8 months ago

1.0.0

8 months ago