1.0.0 • Published 1 year ago
cjh_tools v1.0.0
安装
npm install cjh_tools
导入
const cjh_tools = require('cjh_tools')
格式化时间
// 调用dateFormat 对时间进行格式化
const dtStr = cjh_tools.dataFormat(new Date())
// 结果 2023-2-17 12:00:00
console.log(dtStr)
转义HTML中的特殊字符
// 待转换的HTML字符串
const html = '<h1 style="color:red">123123</h1>'
// 调用htmlEscape方法进行转换
let htmlstr = cjh_tools.htmlEscape(html)
// 转换结果 <h1 style="color:red">123123</h1>
console.log(htmlstr)
还原HTML中的特殊字符
// 待转换的HTML字符串
const html = '<h1 style="color:red">123123</h1>'
// 调用htmlEscape方法进行转换
const htmlstr = cjh_tools.htmlEscape(html)
// 调用htmlUnEscape方法进行还原
const html = cjh_tools.htmlUnEscape(htmlstr)
// 输出结果 <h1 style="color:red">123123</h1>
console.log(htmlstr);
开源协议
ISC
1.0.0
1 year ago