1.0.0 • Published 2 years ago

itheima-tools-lzd v1.0.0

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

安装

npm install itheima-tools-lzd

导入

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

格式化时间

//格式化的时间
const dtStr = itheima.dateFormat(new Date())
console.log(dtStr);
//2022-03-05 18-00-31

转义 HTML 中的 特殊字符

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

还原 HTML 中的 特殊字符

//待 还原 的HTML 字符串
const str1 = itheima.htmlUnEscape(htmlStr)
console.log(str1);
//输出的结果<h1title=" abc">这是h1标签<span>123&nbsp; </span></h1title=>

开源协议

ISC