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 🙏

© 2026 – Pkg Stats / Ryan Hefner

zzerocommonutil

v1.0.1

Published

个人写的方法库,持续更新中...

Readme

常用方法工具库


方法1: 返回当前url的主域名 getUrlBase

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | 无 | | |

返回值: 当前url的主域名


方法2: 获取url具体字段的参数 getUrl

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | urlString | 传入地址字符串 | String | | variable | 获取需要的字段 |String |

返回值: 具体参数
const id = getUrl('https://www.baidu.com?id=202&type=333', 'id') // 202

方法3: 创建随机字符串 randomString

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | num | 需要生成的位数(默认4位数) | Number |

返回值: 返回一个随机数字


方法4: 设置cookie setCookie

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | name | 保存cookie名称 | String | | value | 保存值 | 无限制 |

返回值: 无
setCookie('key', '3dd02c2286c3fc68a48a8c84433f9c12') 

方法5: 获取cookie getCookie

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | cname | 需要获取的cookie名称 | String |

返回值: 空值 或者 缓存值
getCookie('key')  // 3dd02c2286c3fc68a48a8c84433f9c12

方法6: 清除cookie clearCookies

清除所有cookie


方法7: 数据深拷贝 deepCopy

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | obj | 将要被复制的对象或数组 | Array ,Object |

返回值: 复制后的对象或数组 (数据深拷贝(JSON.parse(JSON.stringify)对方法不生效{a:()=>{}}))


方法8: 类型断言方法 assert

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | condition | 判断条件,即应该发生的情况 | 无限制 | | msg | 提示语句 | String |

返回值: 无
 assert(a === 3, "a 的值不是3")

方法9: 字符串截取 getStr

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | str | 需要截取的字符串 | String | | len | 需要截取的位置(默认从1开始) | Number |

返回值: 截取后的字符串


方法10: js生成uuid uuidCreate

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | len | uuid长度 | Number | | radix | uuid基数 | Number |

返回值: uuid (无大写模式)


方法11: 加密方法 encrypt

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | code | 需要加密字段 | 无限制 |

返回值: 加密后的字段


方法12: 解密方法 decrypt

| 参数 | 说明 | 字段类型 | | ---- | ---- | ---- | | code | 需要解密字段 | 无限制 |

返回值: 解密后的字段