1.1.0 • Published 5 years ago

mxs-itheima-tools v1.1.0

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

安装

git install itheima-tools

导入

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

格式化时间的用法

// 调用dateFormat方法
const dateStr = itheima.dateFormat(new Date());
// 结果 2020-11-05 09:26:20
console.log(dateStr);

对html中的特殊字符进行转义

// 待转义的html字符
const htmlStr = '<h1 title="哈哈"><span>123&nbsp;</span></h1>';
// 调用htmlEscape方法
const newStr = itheima.htmlEscape(htmlStr);
// 结果 &lt;h1 title=&quot;哈哈&quot;&gt;&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(newStr);

还原html中的特殊字符

// 调用htmlUnEscape方法 
const htmlRes = itheima.htmlUnEscape(newStr);
// 结果  <h1 title="哈哈"><span>123&nbsp;</span></h1>
console.log(htmlRes);

开源协议

ISC

1.1.0

5 years ago