1.0.0 • Published 8 months ago

xiaoniao-tools v1.0.0

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

安装

npm install xiaoniao-tools

导入

const xn = require('xiaoniao-tools')

格式化时间

// 调用 dateFormat() 对时间进行格式化
const dtStr =  xn.dateFormat(new Date())
console.log(dtStr)

转义HTML字符

//定义待转化的HTML字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
// 使用 htmlEscape() 对HTML字符串进行转义
const str = xn.htmlEscape(htmlStr)
// 输出为:&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原HTML字符串

// 定义待还原的HTML字符串
const htmlUnStr = '&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
// 使用 htmlUnEscape() 对普通字符串还原为hmtl字符串
const unStr = xn.htmlUnEscape(htmlUnStr)
// 输出为 <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>
console.log(unStr)

开源协议

ISC