1.0.2 • Published 2 years ago
itcode-tools v1.0.2
npm install itcode-tools
导入
const code = require('itcode-tools')
格式化时间
const time = code.dateFormat(new Date())
console.log(time);//2022-04-27 14:37:14
转义 HTML 中的特殊字符
// 定义了待转换的 HTML 字符
const htmlStr = '<h1 title="abc">这是h1标签</h1>'
// 调用 htmlEscape 方法进行转换
const str = code.htmlEscape(htmlStr)
console.log(str);//<h1 title="abc"&qt;这是h1标签</h1&qt;
还原 HTML 中的特殊字符
// 定义了待还原的 HTML 字符
// 调用 htmlEscape 方法进行转换
const str1 = code.htmlunEscape(str)
console.log(str1);//<h1 title="abc">这是h1标签</h1>
开源协议
ISC