1.0.0 • Published 3 years ago

starr-tools v1.0.0

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

安装

npm install starr-tools

导入

const starr-tools = require('starr-tools')

格式化时间

// 调用 dateFormat() 对时间格式化
const newDT = starr-tools.dateFormat(new Date())
// 结果 2022年09月28日 13:51:51
console.log(newDT)

转义 HTML 中的特殊字符

// 待转换的 html 字符串
const htmlStr = '<h2>这是标题标签</h2>'
// 调用 htmlEscape() 方法进行转换
const newST = starr-tools.htmlEscape(htmlStr)
// 结果 我是转义后的字符串:&lt;h2&gt;这是标题标签&lt;/h2&gt;
console.log('我是转义后的字符串:' + newST)

还原 HTML 中的特殊字符

// 待还原的 html 字符串
const htmlStr = '&lt;h2&gt;这是标题标签&lt;/h2&gt;'
// 调用 htmlUnEscape() 方法进行还原
const hyStr = starr-tools.htmlUnEscape(htmlStr)
// 结果我是还原后的字符串:<h2>这是标题标签</h2>
console.log('我是还原后的字符串:' + hyStr)

开源协议

ISC