1.1.0 • Published 2 years ago

mytools-qiu v1.1.0

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

//包说明文档

安装

npm i mytools

导入

const tools = require('./mytools')

格式化时间

//调用 dateFormat 对时间进行格式化
const date = tools.dateFormat(new Date());
//结果 2022-08-16 11:53:50
console.log(date);

转义 HTML 中的特殊字符

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

还原 HTML 中特殊字符

//待还原的 HTML 字符串
const str2 = tools.htmlUnEscape(htmlStr);
//输出结果 <h1 title="abd">这是h1标签123&nbsp;</h1>
console.log(str2);

开源协议

ISC