1.1.0 • Published 2 years ago
langhua v1.1.0
安装方式
npm install itheima-tools1011 or npm i itheima-tools1011
导入方式
const itheima = require('itheima-tools1011')
格式化时间
// 调用 dateFormat 对时间进行格式化
const date = itheima.format(new Date)
// 结果 2022-10-11 20:20:58
console.log(itheima)
转义HTML中的特殊字符
// 带转换的 HTML 字符串
const beforeHtml = '<h1 title="abc">这是h1标签<span>123 </span></h1>'
// 调用 htmlEscape() 对html字符串进行转义
const afterHtml = itheima.htmlEscape(htmlStr)
// 转义后结果:'<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
console.log(afterHtml)
还原HTML中转义后的字符串
// 转义后的HTML字符串
const beforeHtml = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
// 调用htmlUnEscape() 对转义后的html进行还原
const afterHtml = itheima.htmlUnEscape(beforeHtml)
// 还原后结果:'<h1 title="abc">这是h1标签<span>123 </span></h1>'
console.log(afterHtml)
开源协议
ISC
1.1.0
2 years ago