1.0.0 • Published 2 years ago
foryoung-tools v1.0.0
安装
npm install foryoung-tools
导入
const tools = require('foryoung-tools')
格式化时间
// 调用 dateformat 对时间进行格式化
const time = new Date()
const TIME = tools.dateformat(time)
// 结果 2022-07-12 00:09:36
console.log(TIME)
转义 html 中的特殊字符
// 待转换的 html 字符串
const Str = `<h1 style='color:red'>我喜欢你 </h1>`
// 调用 htmlEscape() 方法 进行转换
const newStr = tools.htmlEscape(Str)
// 结果 <h1 style='color:red'>我喜欢你$amp;nbsp;</h1>
console.log(newStr)
还原 html 中的特殊字符
// 待转换的 html 字符串
const str = `<h1>我细化你</h1>`
// 调用 htmlUnEscape() 方法 进行转换
const newstr = tools.htmlUnEscape(str)
// 结果 <h1>我细化你</h1>
console.log(newstr)
开源协议
ISC
1.0.0
2 years ago