1.0.0 • Published 5 years ago

tian-tools v1.0.0

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

安装

npm install tian-tools

导入

const tian = require('tian-tools')

格式化时间

//调用dateFormat  对时间进行格式化
const dt = tian.dateFormat(new Date())

// 结果  2020-08-05 20:00:00
console.log(dt)

转义HTML 中特殊字符

//待转换的  HTML  字符串
const html = '<h1 title="哈哈"><span style="color: red;">哈哈</span></h1>'

//调用  htmlEscape  方法进行转换
const str = tian.htmlEscape(html)

// 转换的结果 &lt;h1 title=&quot;哈哈&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;哈哈&lt;/span&gt;&lt;/h1&gt;
console.log(str);

还原 HTML 中的特殊字符

// 待还原的  HTML  字符串
const str = '&lt;h1 title=&quot;哈哈&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;哈哈&lt;/span&gt;&lt;/h1&gt;'

//转换后的结果  <h1 title="哈哈"><span style="color: red;">哈哈</span></h1>
console.log(tian.htmlUnEscape(str));

开源协议

  • ISC
1.0.0

5 years ago