1.0.0 • Published 3 years ago

itheima-tools-xiaoming v1.0.0

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

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 &nbsp;</h1>";
// use htmlEscape() to switch
const str = itheima.htmlEscape(htmlStr);
// result
console.log(str);
// &lt;h1 class='abc'&gt;this is h1 tag &amp;nbsp;&lt;/h1&gt;

// 待转换的字符串
const htmlStr = "<h1 class='abc'>这是h1标签&nbsp;</h1>";
// 调用 htmlEscape 方法进行转换
const str = itheima.htmlEscape(htmlStr);
// 输出转换结果
console.log(str);
// &lt;h1 class='abc'&gt;这是h1标签&amp;nbsp;&lt;/h1&gt;

5.还原 HTML 中的特殊字符 HTML UnEscape

// wait for recover
// 待还原的字符串
const str2 = itheima.htmlUnEscape(str);
// result   输出结果
console.log(str2);
// <h1 class='abc'>this is h1 tag &nbsp;</h1>
// <h1 class='abc'>这是h1标签&nbsp;</h1>

6.开源协议 license

ISC