@baiwusanyu/utils-com
Function
downloadFile
根据下载链接下载文件
createHash
基于 hash-sum 生成一个随机哈希
| id | string \ number | (new Date()).getTime().toString() | 生成hash 的 id |
| prefix | string | '' | 自定义前缀 |
| suffix | 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
以对象格式存储缓存
sessionCache.getJSON
以对象格式获取缓存
sessionCache.remove
移除缓存
localCache
基于 localStorage 的缓存函数, 函数与 sessionCache 相同