huiguang-tools
Version:
提供了格式化时间,HTMLEscape的功能
40 lines (33 loc) • 932 B
Markdown
## 安装
```
npm install huiguang-tools
```
## 导入
```js
const huiguang = require('huiguang-tools')
```
## 格式化时间
```js
// 调用 formatTime 对时间进行格式化
const dtStr = huiguang.formatTime(new Date())
// Today's date in Huiguang: 2025年03月03日 20:12:20
console.log(`Today's date in Huiguang: ${dtStr}`)
```
## 转义 HTML 中的特殊字符
```js
// 待转换的 HTML 字符串
const htmlStr = '<h1 title="abc">这是h1标签<span>123 </span></h1>'
// 调用 htmlEscape 方法进行转换
const str = huiguang.htmlEscape(htmlStr)
// <h1 title="abc">这是h1标签<span>123&nbsp;<n></h1>
console.log(str)
```
## 还原 HTML 特殊字符
```js
// 待还原的 HTML 字符串
const str2 = huiguang.htmlUnescape(str)
// <h1 title="abc">这是h1标签<span>123 </span></h1>
console.log(str2)
```
## 开源协议
ISC