1.0.0 • Published 6 months ago

edison-tools v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

安装

npm install edison-tools

导入

const edison-tools = require('edison-tools')

格式化时间

//调用 dateFormat 对时间进行格式化
const newDate = edison-tools.dateFormat(new Date())
console.log(newDate);
//结果 2023-11-04 21:48:06

转义HTML中的特殊字符

//定义待转义的字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</sapn></h1>'
//调用 htmlEscape 对字符串进行转义
const newHtml = edison-tools.htmlEscape(htmlStr)
console.log(newHtml);
//结果 &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/sapn&gt;&lt;/h1&gt;

还原HTML中的特殊字符

//定义待转义的字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</sapn></h1>'
//调用 htmlUnEscape 对字符串进行还原
const newHtml = zhang_tools.htmlUnEscape(htmlStr)
console.log(newHtml);
//结果 <h1 title="abc">这是h1标签<span>123 </sapn></h1>

开源协议

ISC

1.0.0

6 months ago