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

@zanejs/utils

v1.0.5

Published

`@zanejs/utils` is a carefully curated TypeScript utility function library that aggregates high-frequency utility functions used in daily development. Designed with principles of zero dependencies, type safety, and high performance, this library helps dev

Downloads

20

Readme

@zanejs/utils

English | 中文

简介

@zanejs/utils 是一个精心整理的 TypeScript 工具函数库,汇集了日常开发中高频使用的工具函数。本库以零依赖、类型安全、高性能为设计原则,帮助开发者提升开发效率,减少重复代码编写。

核心特性

  • 📦 零依赖 - 不依赖任何第三方库,开箱即用
  • 🛡 完全 TypeScript - 提供完整的类型定义,开发体验优秀
  • 🚀 高性能 - 每个函数都经过性能优化
  • 📚 模块化设计 - 支持按需引入,Tree-shaking 友好

功能模块

1. 数组操作 (array)

  • 数组去重、扁平化、分组
  • 数组差异、交集、并集计算
  • 数组排序、分页、分区
  • 安全元素访问与操作

2. 缓存工具 (cache)

  • 内存缓存管理(LRU、TTL支持)
  • 本地存储封装(localStorage/sessionStorage)
  • 函数结果缓存(memoization)

3. 相等性比较 (equal)

  • 深度相等比较(支持复杂对象、循环引用)
  • 浅层相等比较
  • 特殊值比较(NaN、±0等)

4. 函数工具 (function)

  • 函数节流与防抖
  • 函数柯里化与部分应用
  • 函数组合与管道
  • 惰性求值与缓存

5. 类型判断 (type)

  • 精确类型检测(数组、对象、函数等)
  • 空值检查(null、undefined、空字符串等)
  • 类型转换辅助

6. 数字操作 (number)

  • 精度计算(解决浮点数问题)
  • 数字格式化、千分位分隔
  • 范围限制、随机数生成
  • 单位转换

7. 对象操作 (object)

  • 对象深度合并、克隆
  • 属性路径获取/设置(支持点号与数组路径)
  • 对象过滤、映射、转换
  • 不可变数据操作

8. 响应式数据 (reactive)

  • 简易观察者模式实现
  • 数据变更监听与响应
  • 计算属性与依赖追踪

9. 字符串操作 (string)

  • 模板字符串处理
  • 字符串加密/解密(基础)
  • 格式化(驼峰、连字符、首字母大写等)
  • 字符串验证与提取

安装使用

# 使用 npm
npm install @zanejs/utils

# 使用 yarn
yarn add @zanejs/utils

# 使用 pnpm
pnpm add @zanejs/utils

按需引入

// ES Module
import { deepClone, throttle, isType } from '@zanejs/utils';

// CommonJS
const { debounce, formatNumber } = require('@zanejs/utils');

完整引入

import * as zUtils from '@zanejs/utils';

示例代码

// 数组操作
import { uniqueBy, chunk } from '@zanejs/utils/array';

const users = [{id: 1}, {id: 2}, {id: 1}];
const uniqueUsers = uniqueBy(users, 'id'); // [{id: 1}, {id: 2}]

const chunks = chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]

// 函数工具
import { debounce, memoize } from '@zanejs/utils/function';

const search = debounce((query) => {
  console.log(`搜索: ${query}`);
}, 300);

const factorial = memoize((n) => {
  return n <= 1 ? 1 : n * factorial(n - 1);
});

// 对象操作
import { deepMerge, get } from '@zanejs/utils/object';

const obj1 = { a: { b: 1 } };
const obj2 = { a: { c: 2 } };
const merged = deepMerge(obj1, obj2); // { a: { b: 1, c: 2 } }

const value = get({ user: { name: 'Zane' } }, 'user.name'); // 'Zane'

浏览器支持

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+
  • iOS Safari 12+
  • Android Chrome 60+

开发理念

zane-utils 遵循以下设计原则:

  1. 实用性优先 - 只包含经过实践验证的工具函数
  2. 一致性API - 统一的参数顺序和命名规范
  3. 明确职责 - 每个函数只做好一件事
  4. 向后兼容 - 稳定的 API 设计,重大变更会提供迁移方案

贡献指南

欢迎提交 Issue 和 Pull Request!如果您有常用的工具函数建议,或者发现任何问题,请随时参与贡献。

许可证

MIT © Zane


@zanejs/utils - 让 JavaScript/TypeScript 开发更优雅、更高效!