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

@huafl/tools

v1.3.0

Published

这是一个基于 TypeScript 的 JavaScript 工具库,名为 `@huafl/tools`。该项目基于 Vite 4.x 构建,旨在创建支持 CommonJS 和 ESM 模块的混合包。项目提供了多种实用的工具函数,包括字符串处理、日期格式化、数组操作、对象操作、正则验证等功能。

Readme

@huafl/tools

概述

这是一个基于 TypeScript 的 JavaScript 工具库,名为 @huafl/tools。该项目基于 Vite 4.x 构建,旨在创建支持 CommonJS 和 ESM 模块的混合包。项目提供了多种实用的工具函数,包括字符串处理、日期格式化、数组操作、对象操作、正则验证等功能。

项目最初是从 vite-vanilla-ts-lib-starter 模板创建的,包含完整的构建和测试工具链。

主要功能

核心工具函数

该工具库提供了以下分类的工具函数:

字符串处理

  • maskPhoneNumber() - 手机号掩码
  • checkFileType() - 检查文件类型
  • removeDuplicateStr() - 去除字符串中的重复项
  • generateRandomString() - 生成指定长度的随机字符串
  • toCamelCase() - 驼峰转换
  • toSnakeCase() - 下划线转换
  • toKebabCase() - 连字符转换
  • capitalize() - 首字母大写
  • truncateString() - 截断字符串

数字处理

  • formatNumber() - 千分位格式化数字
  • numberToChinese() - 将数字转换为中文大写

日期处理

  • formatDate() - 格式化日期
  • dateDiffInDays() - 计算两个日期之间的天数差
  • calculateAge() - 计算年龄
  • isLeapYear() - 判断是否为闰年
  • getDaysInMonth() - 获取指定月份的天数

数组处理

  • uniqueArray() - 数组去重
  • chunkArray() - 数组分割
  • flattenArray() - 数组扁平化

对象处理

  • deepClone() - 深拷贝对象
  • deepMerge() - 深度合并对象

URL 处理

  • getUrlParam() - 获取 URL 参数
  • getUrlParams() - 获取 URL 参数对象

正则表达式验证

  • _regs - 包含多种正则表达式(手机号、邮箱、身份证、URL 等)
  • validateIdCard() - 验证身份证号码

函数式工具

  • debounce() - 防抖函数
  • throttle() - 节流函数

其他实用工具

  • generateUUID() - 生成 UUID
  • randomColor() - 随机生成颜色值
  • isMobile() - 检查是否为移动端
  • copyToClipboard() - 复制文本到剪贴板

构建和运行

安装依赖

npm install

构建输出

构建过程会生成以下文件:

  • dist/index.cjs - CommonJS 模块
  • dist/index.mjs - ESM 模块
  • dist/index.iife.js - IIFE 模块(可在浏览器中直接使用)
  • dist/index.d.ts - TypeScript 类型定义文件

使用示例

import { maskPhoneNumber, formatDate, getUrlParam } from "@huafl/tools";

// 手机号掩码
console.log(maskPhoneNumber("13812345678")); // 输出: 138****5678

// 日期格式化
console.log(formatDate(new Date(), "YYYY-MM-DD HH:mm:ss")); // 输出: 2023-01-01 12:00:00

// 获取URL参数
console.log(getUrlParam("http://example.com/?id=123", "id")); // 输出: 123