1.0.0 • Published 2 years ago
itheima-toos-wh v1.0.0
安装
npm install itheima-tools-wh
导入
const itheima = require('itheima-tools-wh')
格式化时间
// 调用 dateFormat 对时间格式化
const resDt = itheima.dateFormat(new Date())
// 结果 2022-01-12 23:36:46
console.log(resDt);
转义 HTML 中的特殊字符
// 待转换的HTML 字符串
const str = '<h1>你是"张三"吗</h1>'
// 调用 htmlEscape 方法进行转换
const newStr = itheima.htmlEscape(str)
// 转换的结果 <h1>你是"张三"吗</h1>
console.log(newStr);
还原 HTML 中的特殊字符
// 待还原的 HTML 字符串
const str1 = "<h1>你是"张三"吗</h1>"
// 调用 htmlUnEscape 方法进行转换
const newStr1 = itheima.htmlUnEscape(str1)
// 输出的结果 <h1>你是"张三"吗</h1>
console.log(newStr1);
开源协议
ISC
1.0.0
2 years ago