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

@zpeak/utils

v1.0.13

Published

@zpeak/utils 工具函数库,提供常用的工具函数,包括文件操作、字符串处理、数组处理、对象处理、日期处理、数字处理、网络工具等。

Readme

@zpeak/utils

zpeak 工具函数库,提供常用的工具函数,包括文件操作、字符串处理、数组处理、对象处理、日期处理、数字处理、网络工具等。

安装

# 使用 npm
npm install @zpeak/utils

# 使用 yarn
yarn add @zpeak/utils

# 使用 pnpm
pnpm add @zpeak/utils

目录结构

src/
├── file/        # 文件操作相关工具函数
├── string/      # 字符串处理相关工具函数
├── array/       # 数组处理相关工具函数
├── object/      # 对象处理相关工具函数
├── date/        # 日期处理相关工具函数
├── number/      # 数字处理相关工具函数
├── network/     # 网络相关工具函数
├── common/      # 通用工具函数
└── index.ts     # 主入口文件,导出所有工具函数

功能模块

file 模块

  • copyToTarget(source, dest): 将目录复制到另一个目录

string 模块

  • capitalize(str): 首字母大写
  • camelToKebab(str): 驼峰转连字符

array 模块

  • unique(arr): 数组去重
  • groupBy(arr, key): 数组分组

object 模块

  • deepClone(obj): 对象深拷贝
  • merge(target, ...sources): 合并对象

date 模块

  • formatDate(date, format): 格式化日期

number 模块

  • formatNumber(num, decimals): 数字格式化
  • clamp(num, min, max): 数字范围限制

network 模块

  • isValidUrl(url): 检查 URL 是否有效

common 模块

  • generateId(length): 生成随机 ID

使用示例

导入所有工具函数

import * as utils from '@zpeak/utils';

// 使用文件操作工具
await utils.copyToTarget('./source', './dest');

// 使用字符串工具
const capitalized = utils.capitalize('hello');
const kebabCase = utils.camelToKebab('helloWorld');

// 使用数组工具
const uniqueArray = utils.unique([1, 2, 2, 3]);
const grouped = utils.groupBy([{ age: 18 }, { age: 20 }], item => item.age);

// 使用对象工具
const cloned = utils.deepClone({ a: 1, b: { c: 2 } });
const merged = utils.merge({ a: 1 }, { b: 2 });

// 使用日期工具
const formattedDate = utils.formatDate(new Date());

// 使用数字工具
const formattedNumber = utils.formatNumber(123.456);
const clamped = utils.clamp(5, 1, 10);

// 使用网络工具
const isValid = utils.isValidUrl('https://example.com');

// 使用通用工具
const id = utils.generateId();

按需导入

import { copyToTarget } from '@zpeak/utils';
import { capitalize, camelToKebab } from '@zpeak/utils';
import { unique, groupBy } from '@zpeak/utils';
import { deepClone, merge } from '@zpeak/utils';
import { formatDate } from '@zpeak/utils';
import { formatNumber, clamp } from '@zpeak/utils';
import { isValidUrl } from '@zpeak/utils';
import { generateId } from '@zpeak/utils';

构建

# 使用 tsc 构建
pnpm build

# 使用 tsup 构建
pnpm build:tsup

测试

pnpm test

许可证

ISC