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

zycd-utils

v1.0.8

Published

一个实用的 TypeScript 工具库,提供了常用的工具函数集合。

Readme

zycd-utils

一个实用的 TypeScript 工具库,提供了常用的工具函数集合。

安装

npm install zycd-utils
# 或
yarn add zycd-utils
# 或
pnpm add zycd-utils

工具函数

URL 工具

  • updateQueryParameter(queryKey: string, queryValue: string): 安全更新 URL 查询参数并保留历史记录
  • getUrlParameter(name: string, url?: string): 获取 URL 中指定参数的值
  • parseUrlParams(url?: string): 解析 URL 参数为对象

日期时间工具

  • formatDate(date: Date | number, format?: string): 格式化日期时间,支持自定义格式
  • getRelativeTime(date: Date | number, now?: Date): 获取相对时间描述(如:3天前)
  • isSameDay(date1: Date | number, date2: Date | number): 判断是否为同一天

存储工具

  • setLocalStorage(key: string, value: any): 设置 localStorage,支持对象自动序列化
  • getLocalStorage<T>(key: string, defaultValue: T): 获取 localStorage,支持对象自动反序列化
  • removeLocalStorage(key: string): 删除 localStorage 中的项
  • clearLocalStorage(): 清空 localStorage

数据验证工具

  • isValidPhone(phone: string): 验证手机号
  • isValidEmail(email: string): 验证邮箱
  • isValidIdCard(idCard: string): 验证身份证号
  • isEmpty(value: any): 验证是否为空值

DOM 操作工具

  • getElementPosition(element: HTMLElement): 获取元素的绝对位置
  • isElementInViewport(element: HTMLElement, partiallyVisible?: boolean): 判断元素是否在视口中可见
  • addEventListenerWithCleanup(element, event, handler, options?): 添加可清理的事件监听器

网络请求工具

  • request<T>(url: string, options?: RequestOptions): 封装的 fetch 请求
  • get<T>(url: string, options?: RequestOptions): GET 请求快捷方法
  • post<T>(url: string, data?: any, options?: RequestOptions): POST 请求快捷方法

数学计算工具

  • add(num1: number, num2: number): 数字精确加法
  • subtract(num1: number, num2: number): 数字精确减法
  • formatNumber(num: number, decimals?: number): 数字千分位格式化
  • random(min: number, max: number, decimals?: number): 生成指定范围的随机数

数据处理工具

  • deepClone<T>(obj: T): 深拷贝对象
  • uniqueArray<T>(arr: T[], key?: keyof T): 数组去重,支持对象数组
  • sortArrayByKey<T>(arr: T[], key: keyof T, order?: 'asc' | 'desc'): 对象数组按指定键排序
  • groupBy<T>(arr: T[], key: keyof T): 分组对象数组

使用示例

import { formatDate, deepClone, isValidEmail } from 'zycd-utils';

// 格式化日期
const date = formatDate(new Date(), 'YYYY-MM-DD');
console.log(date); // 2025-03-31

// 深拷贝对象
const obj = { a: 1, b: { c: 2 } };
const cloned = deepClone(obj);

// 验证邮箱
const isValid = isValidEmail('[email protected]');
console.log(isValid); // true

许可证

ISC