lht-mytools
Version:
提供了格式化时间和HtmlEscape相关的功能
44 lines (38 loc) • 1.33 kB
Markdown
## 安装
```
npm install lht-mytools
```
## 导入
```js
const lht = require('lht-mytools')
```
## 格式化时间的方法
```js
//调用 dateFormat() 方法对事件进行格式化 参数为时间字符串
const dtStr = lht.dateFormat(new Date())
//返回值为一个字符串 2022年12月14日 14:55:30
console.log(dtStr)
```
## 转义html中的特殊字符的方法
```js
//调用 htmlEscape() 方法转义html中的特殊字符 参数为一个字符串
let htmlStr = '<h1 style = "color:red">这是一个h1标签</h1>'
//返回值为字符串: <h1 style = "color:red">这是一个h1标签</h1>
console.log(lht.htmlEscape(htmlStr))
```
## 还原html中的特殊字符
```js
//调用 htmlUnEscape() 方法还原html中的特殊字符 参数为一个字符串
let Str = '<h1 style = "color:red">这是一个h1标签</h1>'
//返回值为一个字符串: <h1 style = "color:red">这是一个h1标签</h1>
console.log(lht.htmlUnEscape(Str))
```
## 生成一个随机数
```js
//调用 randmizer() 方法生成一个随机数 两个参数都必须为整数 且第一个参数不可以大于第二个参数
const num = lht.randmizer(1,9)
//返回值为一个整数类型: [1-9]
console.log(num)
```
## 开源协议
ISC