1.0.0 • Published 2 years ago

chaotools v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

安装

npm install chaotools

导入

const chao = require('chaotools')

格式化时间

//调用 dateFormat 对时间进行格式化
const dtStr = chao.dateFormat(new Date())
console.log(dtStr)
//结果: 2022-01-20 16:06:16

转义 HTML 中的特殊字符

//待转换的字符
const htmlstr = '<h1>;我是标签</h1>'

//调用htmlEsc()方法进行转换
const str = chao.htmlEsc(htmlstr)

console.log(str) // 打印 &lt;h1&gt;我是标签&lt;/h1&gt;

还原 HTML 中的特殊字符

//待转换的字符
const htmlstr = '&lt;h1&gt;我是标签&lt;/h1&gt'

//调用htmlRestore()方法进行转换
const str2 = chao.htmlRestore(htmlstr)

console.log(str2) // 打印 <h1>;我是标签</h1>

开源协议

ISC

1.0.0

2 years ago