1.0.0 • Published 3 years ago
itheima-tools-xiaoming v1.0.0
1.安装 Install
npm i itheima-tools-xiaoming
2.导入 Import
const itheima = require("itheima-tools-xiaoming");
3.格式化时间 dateFormat
// 调用 dateFormat 对时间进行格式化
// Use dateFormat() for formate date
const dtStr = itheima.dateFormat(new Date());
console.log(dtStr);
// 2021-10-15 21:03:46
4.转义 HTML 中的特殊字符 HTML Escape
// raw string
const htmlStr = "<h1 class='abc'>this is h1 tag </h1>";
// use htmlEscape() to switch
const str = itheima.htmlEscape(htmlStr);
// result
console.log(str);
// <h1 class='abc'>this is h1 tag &nbsp;</h1>
// 待转换的字符串
const htmlStr = "<h1 class='abc'>这是h1标签 </h1>";
// 调用 htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlStr);
// 输出转换结果
console.log(str);
// <h1 class='abc'>这是h1标签&nbsp;</h1>
5.还原 HTML 中的特殊字符 HTML UnEscape
// wait for recover
// 待还原的字符串
const str2 = itheima.htmlUnEscape(str);
// result 输出结果
console.log(str2);
// <h1 class='abc'>this is h1 tag </h1>
// <h1 class='abc'>这是h1标签 </h1>
6.开源协议 license
ISC
1.0.0
3 years ago