1.0.0 • Published 5 years ago

learn-tools v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

安装

npm install learn-tools

导入

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

格式化时间用法

//调用 dateFormat() 对时间进行格式化
const date = new Date();
const d = m.dataFormat(date);
console.log(d);
// 输出结果 2020-08-01 18:42:53 本机时间

转义 HTML 中的特殊字符

//定义带转换的HTML 字符串
const htmlstr = '<h1 title="abc">H1标签<span>123  &</span></h1>';
//调用 htmlEscape() 方法
const str = m.htmlEscape(htmlstr);
console.log(str);
//输出结果 &lt;h1 title=&quot;abc&quot;&gt;H1标签&lt;span&gt;123  &amp;&lt;/span&gt;&lt;/h1&gt;

还原 HTML 中的特殊字符

str = '&lt;h1 title=&quot;abc&quot;&gt;H1标签&lt;span&gt;123  &amp;&lt;/span&gt;&lt;/h1&gt;';
const i = m.htmlUnEscape(str);
console.log(i);
//输出结果 <h1 title="abc">H1标签<span>123  &</span></h1>

开源协议

ISC

1.0.0

5 years ago