1.0.0 • Published 6 months ago

ixn-date-tools v1.0.0

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

安装

npm install ixn-date-tools

导入

const tools = require('ixn-date-tools')

格式化时间

// 调用 dateFormat 对时间进行格式化
const dtStr = tools.dateFormat(new Date())
// 结果 2023-12-01 15:28:00
console.log(dtStr)

转义 HTML 中的字符串

// 待转换的HTML字符串
const htmlStr = '<h1 calss="name">hello<span>我是&span</span></h1>'
// 调用 htmlEscape 方法进行转换
const str = tools.htmlEscape(htmlStr)
// 转换的结果 &lt;h1 calss=&quot;name&quot;&gt;hello&lt;span&gt;我是&amp;span&lt;/span&gt;&lt;/h1&gt;
console.log(str)

还原 HTML 中的特殊字符

// 待还原的 HTML 字符串
const str = '&lt;h1 calss=&quot;name&quot;&gt;hello&lt;span&gt;我是&amp;span&lt;/span&gt;&lt;/h1&gt;'
// 使用htmlUnEscape方法进行转换
const htmlStr = tools.htmlUnEscape(str)
// 转换结果:<h1 calss="name">hello<span>我是&span</span></h1>
console.log(htmlStr)

开源协议

1.0.0

6 months ago