1.1.0 • Published 3 years ago
itheima-tools-ztx v1.1.0
安装
npm install itheima-tools-ztx
导入
const itheima = require('itheima-tools-ztx')
格式化时间
//调用dateFormat对时间进行格式化
const dtStr = itheime.dateForma(new Date())
// 结果 2021-01-25 11:20:20
console.log(dtStr)
转义html中的特殊字符
// 待转换的html字符串
const htmlStr = `<h1 title="abc"> 这是h1标签<span>123 </span>我是韩团</h1>`;
// 调用htmlEscape方法进行转换
const newStr = itheima.htmlEscape(htmlStr);
// 输出结果<h1 title="abc"> 这是h1标签<span>123&nbsp;</span>我是韩团</h1>
console.log(newStr);
还原html中的特殊字符
// 待还原的html字符串
const Str = `<h1 title="abc"> 这是h1标签<span>123&nbsp;</span>我是韩团</h1>`;
// 调用htmlUnEscape方法进行转换
const newStr2 = itheima.htmlEscape(Str);
// 输出结果 <h1 title="abc"> 这是h1标签<span>123 </span>我是韩团</h1>
console.log(newStr2);
开源协议
ISC