1.0.1 • Published 1 year ago

joe-tools v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安装方式

nmp install joe-tools

导入方式

const joe = require('joe-tools');

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = joe.dateFormat(new Date());
// 输出的结果 2050年 01月 01号   23:00:00
console.log(dtStr);

转义 HTML 中特殊字符

// 待转换的 HTML 字符串
const htmlStr = '<h1 style="color:red;">h1标签 <span>&nbsp;666</span></h1>';
// 调用 htmlEscape 方法进行转换
const str = joe.htmlEscape(htmlStr);
// 输出的结果 &lt;h1 style=&quot;color:red;&quot;&gt;h1标签 &lt;span&gt;&amp;nbsp;666&lt;/span&gt;&lt;/h1&gt;
console.log(str);

还原 HTML 中特殊字符

// 待还原的 HTML 字符串
const str = '&lt;h1 style=&quot;color:red;&quot;&gt;h1标签 &lt;span&gt;&amp;nbsp;666&lt;/span&gt;&lt;/h1&gt;';
// 调用 htmlUnEscape 方法进行转换
const str1 = joe.htmlEscape(htmlStr);
// 输出的结果 <h1 style="color:red;">h1标签 <span>&nbsp;666</span></h1>
console.log(str);

开源协议

ISC