1.0.0 • Published 2 years ago

itheima-tools-zzy v1.0.0

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

安装

npm i itheima-tools-zzy

##导入

const itheima = require('./itheima-tools-zzy')

格式化时间

//调用dateFrom 对时间进行格式化
const dtStr = itheima.dateFrom(new Date())
// 结果 2022-09-01 22:35:17
console.log(dtStr)

转移HTML 中的特殊字符

//待转化的HTML字符串
const htmlStr = `<h1 title="abc">这是H1标签<span>123&nbsp;</span></h1>`
//调用htmlEscape方法进行转化
const str = itheima.htmlEscape(htmlStr)
//转化结果 &lth1 title=&quotabc&quot&lg这是H1标签&ltspan&lg123&ampnbsp;&lt/span&lg&lt/h1&lg   
console.log(str)

还原HTML中的字符串

//带还原的HTML字符串
const ss = `&lth1 title=&quotabc&quot&lg这是H1标签&ltspan&lg123&ampnbsp;&lt/span&lg&lt/h1&lg `
//调用expStr方法
const sn = itheima.expStr(ss)
//结果 <h1 title="abc">这是H1标签<span>123&nbsp;</span></h1>
console.log(sn)