1.0.0 • Published 3 years ago

itwc-datetools v1.0.0

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

安装

npm install itwc-datetools

导入

const itwc = require('itwc-datetools')

日期时间格式化

//调用dateFormat()进行时间格式化
const dtStr = itwc.dateFormat(new Date())
console.log(dtStr)   // 2022-12-15 15:35:30

转义html中的特殊字符

//带有需要转义的字符
const htmlStr='<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
//调用htmlEscape()方法进行字符的转义
const str =  itwc.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中的特殊字符

//调用htmlUnEscape()方法还原特殊字符
const str1 =  itwc.htmlUnEscape(str)
console.log(str1)   // <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>

开源协议

ISC