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

js-utils-toolkit-helper

v1.0.1

Published

A collection of useful JavaScript utility functions for common programming tasks

Readme

JavaScript Utility Toolkit

一个功能丰富的JavaScript工具函数库,提供日常开发中常用的工具函数。

安装

npm install js-utils-toolkit

使用方法

ES6 模块导入

import { stringUtils, arrayUtils, objectUtils, validationUtils, dateUtils, mathUtils } from 'js-utils-toolkit';

// 或者导入默认导出
import utils from 'js-utils-toolkit';

CommonJS 导入

const { stringUtils, arrayUtils, objectUtils, validationUtils, dateUtils, mathUtils } = require('js-utils-toolkit');

功能特性

1. 字符串工具 (stringUtils)

import { stringUtils } from 'js-utils-toolkit';

// 驼峰命名
console.log(stringUtils.toCamelCase('hello-world')); // 'helloWorld'

// 帕斯卡命名
console.log(stringUtils.toPascalCase('hello-world')); // 'HelloWorld'

// 蛇形命名
console.log(stringUtils.toSnakeCase('helloWorld')); // 'hello_world'

// 字符串截断
console.log(stringUtils.truncate('这是一个很长的字符串', 5)); // '这是一...'

2. 数组工具 (arrayUtils)

import { arrayUtils } from 'js-utils-toolkit';

// 数组去重
console.log(arrayUtils.unique([1, 2, 2, 3, 3, 3])); // [1, 2, 3]

// 数组分块
console.log(arrayUtils.chunk([1, 2, 3, 4, 5], 2)); // [[1, 2], [3, 4], [5]]

// 数组扁平化
console.log(arrayUtils.flatten([1, [2, [3, 4]], 5])); // [1, 2, 3, 4, 5]

// 数组随机排序
console.log(arrayUtils.shuffle([1, 2, 3, 4, 5])); // 随机排序的数组

3. 对象工具 (objectUtils)

import { objectUtils } from 'js-utils-toolkit';

const obj = { a: 1, b: { c: 2 }, d: [3, 4] };

// 深度克隆
const cloned = objectUtils.deepClone(obj);

// 对象合并
const merged = objectUtils.merge({ a: 1 }, { b: 2 }, { c: 3 });

// 选取属性
const picked = objectUtils.pick({ a: 1, b: 2, c: 3 }, ['a', 'b']);

// 排除属性
const omitted = objectUtils.omit({ a: 1, b: 2, c: 3 }, ['a']);

4. 验证工具 (validationUtils)

import { validationUtils } from 'js-utils-toolkit';

// 邮箱验证
console.log(validationUtils.isEmail('[email protected]')); // true

// 手机号验证(中国)
console.log(validationUtils.isPhone('13800138000')); // true

// 身份证验证(中国)
console.log(validationUtils.isIdCard('110101199001011234')); // true

// URL验证
console.log(validationUtils.isUrl('https://example.com')); // true

5. 日期工具 (dateUtils)

import { dateUtils } from 'js-utils-toolkit';

const date = new Date('2023-01-01');

// 日期格式化
console.log(dateUtils.formatDate(date, 'YYYY-MM-DD HH:mm:ss'));

// 相对时间
const pastDate = new Date(Date.now() - 30 * 60 * 1000); // 30分钟前
console.log(dateUtils.getRelativeTime(pastDate)); // '30分钟前'

6. 数学工具 (mathUtils)

import { mathUtils } from 'js-utils-toolkit';

// 随机整数
console.log(mathUtils.randomInt(1, 100)); // 1-100之间的随机整数

// 数值限制
console.log(mathUtils.clamp(150, 0, 100)); // 100

// 数字格式化
console.log(mathUtils.formatNumber(1234567)); // '1,234,567'

API 文档

stringUtils

  • toCamelCase(str) - 转换为驼峰命名
  • toPascalCase(str) - 转换为帕斯卡命名
  • toSnakeCase(str) - 转换为蛇形命名
  • truncate(str, length, suffix) - 字符串截断

arrayUtils

  • unique(arr) - 数组去重
  • chunk(arr, size) - 数组分块
  • flatten(arr, depth) - 数组扁平化
  • shuffle(arr) - 数组随机排序

objectUtils

  • deepClone(obj) - 深度克隆对象
  • merge(...objects) - 合并多个对象
  • pick(obj, keys) - 选取指定属性
  • omit(obj, keys) - 排除指定属性

validationUtils

  • isEmail(email) - 邮箱验证
  • isPhone(phone) - 手机号验证(中国)
  • isIdCard(idCard) - 身份证验证(中国)
  • isUrl(url) - URL验证

dateUtils

  • formatDate(date, format) - 日期格式化
  • getRelativeTime(date) - 相对时间

mathUtils

  • randomInt(min, max) - 随机整数
  • clamp(value, min, max) - 数值限制
  • formatNumber(num) - 数字格式化

浏览器支持

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

开发

# 克隆项目
git clone https://github.com/HrCode-w/npm1.git

# 安装依赖
npm install

# 运行测试
npm test

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT License

更新日志

v1.0.0

  • 初始版本发布
  • 包含6大类工具函数
  • 支持ES6模块和CommonJS