itheima-tools-qz

1.0.0 • Public • Published

安装

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

Package Sidebar

Install

npm i itheima-tools-qz

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

2.94 kB

Total Files

5

Last publish

Collaborators

  • yukiii