1.0.0 • Published 2 years ago

itheima-tools-qz v1.0.0

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

安装

npm install itheima-tools-qz

导入

const itheima = require('./itheima-tools-qz');

格式化时间

// 调用 dateFormat 方法对时间进行格式化
const time = itheima.dateFormat(new Date());
// 打印的结果  2022-05-23 11:21:00
console.log(time);

转义 HTML 中的特殊字符

// 待转换的 HTML 字符串
const htmlStr = '<h1 class="dl">哈哈哈哈哈 <span> 哈哈哈&nbsp;</span></h1>'
// 调用 htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlStr);
// 打印结果  &it;h1 class=&quot;dl&quot;&gt;哈哈哈哈哈 &it;span&gt; 哈哈哈&amp;nbsp;&it;/span&gt;&it;/h1&gt;
console.log(str);

还原 HTML 中的特殊字符

// 调用 htmlUnEscape 方法还原字符串
const str2 = itheima.htmlUnEscape(str);
// 打印结果  <h1 class="dl">哈哈哈哈哈 <span> 哈哈哈&nbsp;</span></h1>
console.log(str2);

开源协议

ISC