1.0.0 • Published 2 years ago
itheima-tools-xh v1.0.0
安装
npm i itheima-tools-xh
导入
const itheima = require('./itheima-tools/index')
格式化时间
//调用 dateFormat 函数格式化时间
const dtStr = itheima.dateFormat(new Date())
//返回结果 2022-05-20 20:36:59
console.log(dtStr);
转义html字符的函数
//带转换的html字符串
const htmlStr = '<h1 title="abc">这是一个h1标题<span>123 ;</span></h1>'
//调用 htmlEscape 函数进行转换
const str = itheima.htmlEscape(htmlStr)
//返回结果 <h1 title="abc">这是一个h1标题<span>123&nbsp;;</span></h1>
console.log(str);
还原html字符串的函数
//待转换的html字符串
const str2 = itheima.htmlUnEscape(str)
//返回结果 <h1 title="abc">这是一个h1标题<span>123 ;</span></h1>
console.log(str2);
开源协议
ISC
1.0.0
2 years ago