1.0.0 • Published 3 years ago

ithema-hero v1.0.0

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

安装

npm intall ithema-hero

导入

const ithema=require('ithema-hero')

格式化时间

//调用dateFormat()方法对时间格式化
const dt = ithema.dateFormat(new Date())
//结果 2021-01-08 15:36:13
console.log(dt);

转义html中的特殊字符

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

还原html中的特殊字符

//带还原的html字符串 newStr
//调用htmlUnEscape()方法转换
const str2 = ithema.htmlUnEscape(newStr)
//结果 <h1 title="abc">这是一个h1标签<span>123&nbsp;</span></h1>
console.log(str2);

开源协议

ISC
1.0.0

3 years ago