1.0.1 • Published 1 year ago

lht-mytools v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安装

npm install lht-mytools

导入

const lht = require('lht-mytools')

格式化时间的方法

//调用 dateFormat() 方法对事件进行格式化    参数为时间字符串 
const dtStr = lht.dateFormat(new Date())
//返回值为一个字符串 2022年12月14日 14:55:30
console.log(dtStr)

转义html中的特殊字符的方法

//调用 htmlEscape() 方法转义html中的特殊字符    参数为一个字符串
let htmlStr = '<h1 style = "color:red">这是一个h1标签</h1>'
//返回值为字符串:     &lt;h1 style = &quot;color:red&quot;&gt;这是一个h1标签&lt;/h1&gt;
console.log(lht.htmlEscape(htmlStr))

还原html中的特殊字符

//调用 htmlUnEscape() 方法还原html中的特殊字符   参数为一个字符串
let Str = '&lt;h1 style = &quot;color:red&quot;&gt;这是一个h1标签&lt;/h1&gt;'
//返回值为一个字符串:    <h1 style = "color:red">这是一个h1标签</h1>
console.log(lht.htmlUnEscape(Str))

生成一个随机数

//调用 randmizer() 方法生成一个随机数   两个参数都必须为整数 且第一个参数不可以大于第二个参数
const num = lht.randmizer(1,9)
//返回值为一个整数类型:  [1-9]
console.log(num)

开源协议

ISC