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 🙏

© 2025 – Pkg Stats / Ryan Hefner

qinhaojoyc-utils

v1.0.8

Published

一个简单的工具库

Readme

chive-utils

本工具库是我的一些小工具,目前仅包括一些常用的工具函数,以及一些常用的正则表达式。后面会持续更新。

安装

npm install chive-utils

tools的使用

| 函数名 | 参数 | 描述 | | --- | --- | --- | | sleep | ms | 传入毫秒数,延迟执行后续方法 | | getParamsType | params | 获取参数类型如stringnumberobjectarrayfunctionnullundefined等 | | cutStr | str, len | 截取字符串返回指定长度的字符串,超出部分用省略号代替 | | debounce | fn, delay | 防抖函数:持续触发时,在传入的毫秒内只会执行最一次的函数调用,一直延迟到不触发为止 | | throttle | fn, delay | 节流函数:持续触发时,在传入的毫秒内只会执行第一次的函数调用,超过该时间才会执行第二次的函数调用 | | shallowCopy | target | 浅拷贝:只会复制对象的第一层属性,而对象内部的引用类型属性仍然指向原对象的内部数据。 | | deepCopy | target | 深拷贝:深拷贝会递归地复制对象的所有层级,使得新对象与原对象完全隔离,不存在引用共享。 | | flatten | arr | 数组扁平化 |

示例:

import { tools } from 'chive-utils'

tools.sleep(1000).then(() => {})
tools.getParamsType(20)
tools.cutStr('bjvjadsasdasd', 5)

// 防抖节流
tools.debounce(() => {}, 300)
tools.throttle(() => {}, 300)

// 浅拷贝 深拷贝
const obj = { age: 30, children: [ { age: 3 } ] }
tools.shallowCopy(obj)
tools.deepCopy(obj)

// 数组扁平化
tools.flatten([ 1, 2, [ 3, 4, [ 5, 6 ] ] ])

validate的使用

| 函数名 | 参数 | 描述 | | --- | --- | --- | | validate | rule, value | 支持传入正则和值进行校验,返回true/false |

示例:

import { validatorReg, validate } from "chive-utils";

validate(validatorReg.isPhoneNumber, value);

validatorReg的使用

| 属性 | 描述 | | --- | --- | | isEmail | 校验邮箱 | | isPhoneNumber | 手机号码验证 | | isTelNumber | 固定电话号码验证 | | isIdCard | 身份证号码验证 | | isBankCard | 银行卡号 | | isZHCNUserName | 大陆居民姓名验证 | | isEmoJi | 表情验证 | | isHighPassword | 8-16位由数字字母或英文特殊字符(三者都要有)的密码校验 | | isPassword | 由数字字母英文特殊字符任意组合的密码校验 | | isNumber | 匹配正整数 | | isNumberWithZero | 匹配整数 |

validatorReg 是正则匹配,可以直接使用。

数据结构使用

Stack 类

| 方法 | 描述 | | --- | --- | | push(element) | 向栈中添加元素 | | pop | 从栈中移除元素并返回 | | peek | 查看栈顶元素但不移除 | | isEmpty | 检查栈是否为空 | | size | 获取栈的大小 | | clear | 清空栈 |

示例:

import { Stack } from "chive-utils";

const stack = new Stack();
stack.push(1);
stack.push(2);
stack.push(3);
console.log(stack.pop());    // 输出: 3
console.log(stack.peek());   // 输出: 2
console.log(stack.isEmpty()); // 输出: false
console.log(stack.size());   // 输出: 2

Queue 类

| 方法 | 描述 | | --- | --- | | enqueue(element) | 入队操作,将元素添加到队列的末尾 | | dequeue | 出队操作,移除队列的第一个元素并返回它 | | front | 查看队列的第一个元素 | | isEmpty | 检查队列是否为空 | | size | 获取队列的大小 | | clear | 清空队列 | | print | 打印队列中的元素 |

示例:

// 使用Queue类
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.print(); // 输出: 1,2,3
console.log(queue.dequeue()); // 输出: 1
queue.print(); // 输出: 2,3