1.0.0 • Published 3 years ago

yuanmashidai-wangzhiheng v1.0.0

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

这是自己创建包的详细介绍

安装

npm install itheima-tools

导入

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

格式化时间

// 测试格式化时间
const date = itheima.dataFormat(new Date());
// 结果 2022-05-24 22:28:27
console.log(date); 

转义 HTML 中的特殊字符

// 测试带转换 HTML 字符串 
const htmlStr = '<h1 class="title">这是h1标签</h1>';
// 调用 htmlEscape 方法进行转换
const newHTMLStr = itheima.HTMLEscape(htmlStr);
// 结果: &lt;h1 class=&quot;title&quot;&gt;这是h1标签&lt;/h1&gt;
console.log(newHTMLStr); 

还原 HTML 中的特殊字符

// 测试 待还原 HTML 特殊字符
const str = itheima.HTMLUnEscape(newHTMLStr);
// 结果: <h1 class="title">这是h1标签</h1>
console.log(str);

开源协议

ISC