1.0.0 • Published 5 years ago
shy-tools v1.0.0
安装
npm install shy-tools
引入
const shy = require('shy-tools')
格式化时间
// 调用 dateFormat 对时间进行格式化
const str = shy.dateFormat(new Date())
// 结果 2020-10-16 15:19:13
console.log(Str)
转义 HTML 中的特殊字符
// 带转换的 HTML 字符串
const str2 = '<h1 title="logo">标题</h1>'
// 调用 htmlEscape 方法进行转换
const str3 = shy.htmlEscape(str2)
// 转换的结果 <h1 title="logo">标题</h1>-----被转义了
console.log(str3);
还原 HTML 中的特殊字符
// 待还原的 HTML 字符串
const str4 = shy.htmlUnEscape(str3)
// 输出的结果 <h1 title="abc">这是h1标签<span>123 </span></h1>
console.log(str4);
开源协议
ISC
1.0.0
5 years ago