1.0.0 • Published 2 years ago
osctools v1.0.0
安装
npm install osctools
导入
const tools = require("osctools")
格式化时间
//调用 dateFormat() 对时间进行格式化
const dt = tools.dateFormat(new Date())
//结果 2022-02-03 15:40:43
console.log(dt);
转义 HTML 中的特殊字符
//待转义的 HTML 字符串
const htmlStr1 = '<h1 style="color:red;"> :;ooo</h1>'
//调用 htmlEscape() 进行转义
const newStr = tools.htmlEscape(htmlStr1)
//结果 <h1 style="color:red;">&nbsp:;ooo</h1>
console.log(newStr);
还原 HTML 中的特殊字符
// newStr 为待还原的 HTML 字符串
// 调用 htmlUnEscape() 进行还原
const htmlStr2 = tools.htmlUnEscape(newStr)
//结果 <h1 style="color:red;"> :;ooo</h1>
console.log(htmlStr2);
开源协议
ISC
1.0.0
2 years ago