1.0.18 • Published 2 years ago
@baiwusanyu/utils-com
Function
downloadFile
根据下载链接下载文件
参数 | 参数类型 | 默认值 | 说明 |
---|
url | string | - | 下载链接 |
createHash
基于 hash-sum
生成一个随机哈希
参数 | 参数类型 | 默认值 | 说明 |
---|
id | string \ number | (new Date()).getTime().toString() | 生成hash 的 id |
prefix | string | '' | 自定义前缀 |
suffix | string | '' | 自定义后缀 |
返回值 | 返回类型 | 说明 |
---|
res | string | 生成的哈希结果 |
debounce
防抖函数返回一个新的函数,这个新函数会在 wait 时间内被连续调用时,
会取消上一次调用并重新开始等待 wait 时间。
参数 | 参数类型 | 默认值 | 说明 |
---|
func | T extends (...args: any[]) => any | - | 需要进行防抖的函数 |
wait | number | '' | 等待时间(毫秒),即在该时间内没有新的调用时才会真正地执行 func |
返回值 | 返回类型 | 说明 |
---|
debounceFn | (...args: Parameters<T>) => void | 防抖函数 |
throttle
节流函数返回一个新的函数,这个新函数会在 wait 时间内被连续调用时,
只会执行第一次调用,并在 wait 时间后才能再次执行。
参数 | 参数类型 | 默认值 | 说明 |
---|
func | T extends (...args: any[]) => any | - | 需要进行节流的函数 |
wait | number | '' | 等待时间(毫秒),即在该时间内只能执行一次 func |
返回值 | 返回类型 | 说明 |
---|
throttleFn | (...args: Parameters<T>) => void | 节流函数 |
copyText
将字符串复制到粘贴板
参数 | 参数类型 | 默认值 | 说明 |
---|
content | string | - | 复制内容 |
resolve | () => void | - | 调用成功回调 |
err | (err: any) => void | - | 调用错误回调 |
sessionCache
基于 sessionStorage 的缓存函数
sessionCache.set
存储缓存
参数 | 参数类型 | 默认值 | 说明 |
---|
key | string | - | key |
value | string | - | 值 |
sessionCache.get
获取缓存
sessionCache.setJSON
以对象格式存储缓存
参数 | 参数类型 | 默认值 | 说明 |
---|
key | string | - | key |
value | any | - | 值 |
sessionCache.getJSON
以对象格式获取缓存
sessionCache.remove
移除缓存
localCache
基于 localStorage 的缓存函数, 函数与 sessionCache 相同