npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@baiwusanyu/utils-com

v1.0.18

Published

## Function

Downloads

6,109

Readme

@baiwusanyu/utils-com

Function

downloadFile

根据下载链接下载文件

| 参数 | 参数类型 | 默认值 | 说明 | |--------|---------------------------------|---------|----------| | url | string | - | 下载链接 |

createHash

基于 hash-sum 生成一个随机哈希

| 参数 | 参数类型 | 默认值 | 说明 | |-----|-------------------|-------------------------------------|----------------| | id | string \ number | (new Date()).getTime().toString() | 生成hashid | | 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

获取缓存

| 参数 | 参数类型 | 默认值 | 说明 | |--------|----------------------|---------|------| | key | string | - | key |

| 返回值 | 返回类型 | 说明 | |-----|----------|------| | res | string | 缓存数据 |

sessionCache.setJSON

以对象格式存储缓存

| 参数 | 参数类型 | 默认值 | 说明 | |-------|----------|---------|-----| | key | string | - | key | | value | any | - | 值 |

sessionCache.getJSON

以对象格式获取缓存

| 参数 | 参数类型 | 默认值 | 说明 | |--------|----------------------|---------|------| | key | string | - | key |

| 返回值 | 返回类型 | 说明 | |-----|-------|------| | res | any | 缓存数据 |

sessionCache.remove

移除缓存

| 参数 | 参数类型 | 默认值 | 说明 | |--------|----------------------|---------|------| | key | string | - | key |

localCache

基于 localStorage 的缓存函数, 函数与 sessionCache 相同