UNPKG

itheima-tools-cs

Version:

提供了格式化时间,HTMLEscape的功能

35 lines (31 loc) 898 B
## 安装 ``` npm install itheima-tools-cs ``` ## 导入 ``` const itheima = require('itheima-tools-cs') ``` ## 格式化时间 ```js // 调用dateFormat对时间进行格式化 const dtStr = itheima.dateFormat(new Date()); // 结果 2022-10-26 20:07:07 console.log(dtStr); ``` ## 转义HTML中的特殊字符 ```js // 定义了待转换的HTML字符串 const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'; // 调用htmlEscape方法进行转换 const str = itheima.htmlEscape(htmlStr); // 输出结果:&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt; console.log(str); ``` ## 还原HTML中的特殊字符 ```js // 定义了待还原的HTML字符串 const str2 = itheima.htmlUnEscape(str); // 输出结果:<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1> console.log(str2); ```