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

@jckj/toolkit

v1.0.4

Published

A lightweight TypeScript utility library featuring various functions for common tasks.

Readme

Toolkit - JavaScript 工具库

Toolkit 是一个轻量级的 JavaScript 工具库,提供了丰富的函数式编程工具,包括数组操作、数学计算、对象处理、函数式工具等功能。

安装

npm install @jckj/toolkit
# 或
yarn add @jckj/toolkit
# 或
pnpm add @jckj/toolkit

特性

📦 轻量级:按需引入,体积小 🔧 功能丰富:涵盖数组、对象、数学、字符串等常用操作 🎯 类型安全:完整的 TypeScript 支持 🚀 现代 JavaScript:使用 ES Module 格式 🛡️ 可靠稳定:经过充分测试,生产可用

文档目录

数组操作

  • at - 安全获取数组元素
  • chunk - 将数组分割成多个小块
  • compact - 过滤掉数组中的假值
  • difference - 返回在数组中但不在其他数组中的元素
  • intersection - 返回多个数组中都存在的元素
  • intersectionBy - 基于指定条件返回多个数组中都存在的元素
  • maxBy - 返回通过条件函数比较后的最大值
  • orderBy - 对数组进行排序
  • remove - 移除数组中满足条件的元素
  • sample - 从数组中随机选取一个元素
  • shuffle - 打乱数组顺序
  • uniq - 数组去重
  • union - 合并多个数组并去重
  • without - 返回排除指定值后的数组
  • xor - 返回只在其中一个数组中出现的元素

数学计算

  • clamp - 限制数值在指定范围内
  • inRange - 检查数值是否在指定范围内
  • lerp - 线性插值
  • median - 计算数组的中位数
  • medianBy - 基于条件函数计算中位数
  • percentCalc - 计算百分比并处理精度问题
  • random - 生成指定范围内的随机数
  • randomInt - 生成指定范围内的随机整数
  • range - 生成指定范围内的数字数组
  • round - 四舍五入到指定小数位

对象操作

  • clone - 深拷贝对象
  • cloneDeep - 深拷贝对象(支持循环引用)
  • cloneStructured - 结构化克隆
  • findKey - 查找对象的键
  • invert - 反转对象的键值对
  • merge - 合并多个对象
  • omit - 排除对象的指定属性
  • omitBy - 基于条件排除对象的属性
  • pick - 选取对象的指定属性
  • pickBy - 基于条件选取对象的属性

函数式工具

  • debounce - 防抖函数
  • throttle - 节流函数
  • memoize - 缓存函数结果
  • negate - 反转函数返回值
  • once - 确保函数只执行一次

字符串操作

  • capitalize - 首字母大写
  • escape - 转义 HTML 字符
  • unescape - 反转义 HTML 字符
  • frequencyStatistics - 统计字符频率
  • words - 将字符串分割成单词
  • lowerCase - 转换为小写
  • pascalCase - 转换为帕斯卡命名
  • randomString - 生成随机字符串
  • randomColor - 生成随机颜色
  • reverse - 反转字符串

判断函数

  • isArray - 判断是否为数组
  • isBigInt - 判断是否为 BigInt
  • isBlob - 判断是否为 Blob
  • isBoolean - 判断是否为布尔值
  • isBrowser - 判断是否在浏览器环境
  • isBuffer - 判断是否为 Buffer
  • isDate - 判断是否为 Date
  • isEmptyObject - 判断是否为空对象
  • isError - 判断是否为 Error
  • isFile - 判断是否为 File
  • isJson - 判断是否为有效 JSON
  • isLength - 判断是否为有效长度
  • isMap - 判断是否为 Map
  • isNil - 判断是否为 null 或 undefined
  • isNull - 判断是否为 null
  • isNumber - 判断是否为数字
  • isPlainObject - 判断是否为普通对象
  • isPrimitive - 判断是否为基本类型
  • isPromise - 判断是否为 Promise
  • isRegExp - 判断是否为 RegExp
  • isSet - 判断是否为 Set
  • isString - 判断是否为字符串
  • isSymbol - 判断是否为 Symbol
  • isUndefined - 判断是否为 undefined
  • isWeakMap - 判断是否为 WeakMap
  • isWeakSet - 判断是否为 WeakSet

API 参考

数组操作

  • at

    安全获取数组元素,支持负索引。

import { at } from "toolkit";

const array = [1, 2, 3, 4, 5];
console.log(at(array, [1, 3])); // [2, 4]
console.log(at(array, [-1])); // [5]
  • chunk

    将数组分割成指定大小的多个子数组。

import { chunk } from "toolkit";

const array = [1, 2, 3, 4, 5];
console.log(chunk(array, 2)); // [[1, 2], [3, 4], [5]]
  • compact

    过滤掉数组中的假值。

import { compact } from "toolkit";

const array = [0, 1, false, 2, "", 3];
console.log(compact(array)); // [1, 2, 3]
import { chunk } from "toolkit";

const array = [1, 2, 3, 4, 5];
console.log(chunk(array, 2)); // [[1, 2], [3, 4], [5]]

数学计算

  • clamp 限制数值在指定范围内。
import { clamp } from "toolkit";
console.log(clamp(10, 0, 5)); // 5
console.log(clamp(-10, 0, 5)); // 0
  • random 生成指定范围内的随机数。
import { random } from "toolkit";

console.log(random(0, 10)); // 0-10之间的随机数

函数式工具

  • debounce 创建一个防抖函数。
import { debounce } from "toolkit";

const debouncedFn = debounce((value) => {
  console.log("Debounced:", value);
}, 300);

// 在事件处理中使用
document.getElementById("input").addEventListener("input", (e) => {
  debouncedFn(e.target.value);
});

字符串操作

  • capitalize 将字符串首字母大写。
import { capitalize } from "toolkit";

console.log(capitalize("hello world")); // 'Hello world'
  • randomString 生成指定长度的随机字符串。
import { randomString } from "toolkit";

console.log(randomString(8)); // 8位随机字符串

许可证

MIT License

  • 这个 Markdown 文档提供了完整的库介绍、功能列表和使用示例。您可以根据实际需求