1.0.0 • Published 5 years ago
itheima-tools-wyt v1.0.0
安装
npm install itheima-tools
导入
const itheima = require('itheima-tools')
格式化时间
// 调用dateFormat()对时间进行格式化
const dt = itheima.dateFormat(new Date())
// 结果2020-08-21 22:28:14
console.log(dt);
转义HTML中特殊字符
// 待转换的字符串
const htmlStr = '<h1 style = "color:red;">你好! © <span>小黄! </span></h1>'
// 调用htmlEscape()方法转换字符串
const str = itheima.htmlEscape(htmlStr)
// 转换结果:<h1 style = "color:red;">你好! &copy; <span>小黄! </span></h1>
console.log(str);
还原HTML中特殊字符
// 调用htmlUnEscape()方法还原字符串
const rowHtml = itheima.htmlUnEscape(str)
// 转换结果:<h1 style = "color:red;">你好! © <span>小黄! </span></h1>
console.log(rowHtml);
开源许可协议
ISC
1.0.0
5 years ago