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

pillar-utils

v1.0.8

Published

Pillar Utils 是一个基于 TypeScript 开发的工具函数库,提供了一系列常用的工具函数,包括日期处理、正则表达式、数字格式化、对象操作和枚举处理等功能。该库旨在提高开发效率,减少重复代码,提供统一的工具函数接口。

Readme

Pillar Utils

Pillar Utils 是一个基于 TypeScript 开发的工具函数库,提供了一系列常用的工具函数,包括日期处理、正则表达式、数字格式化、对象操作和枚举处理等功能。该库旨在提高开发效率,减少重复代码,提供统一的工具函数接口。

特性

  • 📦 模块化设计:每个功能模块独立,可按需引入
  • 🔒 类型安全:基于 TypeScript,提供完整的类型定义
  • 🧪 全面测试:使用 Jest 进行单元测试,确保代码质量
  • 📚 详细文档:每个模块都有详细的使用文档和示例
  • 🌳 轻量级:依赖少,体积小,性能高

安装

npm install pillar-utils
# 或
yarn add pillar-utils
# 或
pnpm add pillar-utils

使用方法

模块化引入

// 引入日期工具
import { dateUtils } from 'pillar-utils';
const { formatDate } = dateUtils;

// 引入正则工具
import { regularUtils } from 'pillar-utils';
const { regularValid } = regularUtils;

// 引入数字工具
import { numberUtils } from 'pillar-utils';
const { thousandSeparator } = numberUtils;

// 引入对象工具
import { objectUtils } from 'pillar-utils';
const { deepCopy, emptyToNull } = objectUtils;

// 引入枚举工具
import { enumUtils } from 'pillar-utils';
const { create, getEnumOptions } = enumUtils;

// 引入文件工具
import { fileUtils } from 'pillar-utils';
const { formatSize, downloadFileStream, downloadStreamData } = fileUtils;

全量引入

import * as utils from 'pillar-utils';

// 使用日期工具
utils.dateUtils.formatDate(new Date());

// 使用正则工具
utils.regularUtils.regularValid('13800138000', 'phone');

// 使用数字工具
utils.numberUtils.thousandSeparator(1234567.89);

// 使用对象工具
utils.objectUtils.deepCopy({ name: 'test' });

// 使用枚举工具
utils.enumUtils.create([
  { value: 'ACTIVE', label: '活跃' },
  { value: 'INACTIVE', label: '非活跃' }
]);

// 使用文件工具
utils.fileUtils.formatSize(1024);
utils.fileUtils.downloadFileStream(blobData, 'example.pdf', 'application/pdf');

// 在异步函数中使用downloadStreamData
async function downloadFile() {
  const success = await utils.fileUtils.downloadStreamData(response, 'example.pdf');
  if (success) {
    console.log('下载成功');
  } else {
    console.log('下载失败');
  }
}

模块文档

Pillar Utils 包含以下五个主要模块,每个模块都有详细的文档和示例:

Date 工具集合

提供日期处理相关的工具函数,基于 dayjs 库构建,包括日期格式化、日期范围处理、相对时间计算等功能。

主要功能:

  • 日期格式化
  • 日期范围处理
  • 相对时间计算
  • 时间戳转换

Regular 工具集合

提供正则表达式处理相关的工具函数,包括常用正则表达式维护、获取正则表达式和正则校验等功能。

主要功能:

  • 手机号验证
  • 邮箱验证
  • 正则表达式管理
  • 正则验证工具

Number 工具集合

提供数字处理相关的工具函数,目前主要包含数字千分位格式化功能。

主要功能:

  • 数字千分位格式化
  • 小数位数控制

Object 工具集合

提供对象处理相关的工具函数,包括对象深拷贝、空值处理、数据检查等功能。

主要功能:

  • 对象深拷贝
  • 空值处理
  • 数据检查
  • 对象清理

Enum 工具集合

提供枚举处理相关的工具函数,包括枚举创建、枚举值获取、枚举标签获取等功能。

主要功能:

  • 枚举创建
  • 枚举值获取
  • 枚举标签获取
  • 枚举选项生成

File 工具集合

提供文件处理相关的工具函数,包括文件大小格式化和文件流下载功能。

主要功能:

  • 文件大小格式化
  • 文件流下载
  • 浏览器兼容性处理

开发

环境要求

  • Node.js >= 14
  • TypeScript >= 4.0

安装依赖

npm install
# 或
yarn install
# 或
pnpm install

开发模式

# 启动监听模式
npm run watch

# 运行测试
npm test

# 运行测试并监听变化
npm run test:watch

# 运行测试覆盖率
npm run test:coverage

构建

# 构建所有模块
npm run build

# 构建 ESM 模块
npm run build:esm

# 构建 CommonJS 模块
npm run build:cjs

# 清理构建产物
npm run clean

代码检查

# 运行 ESLint 检查
npm run lint

贡献

欢迎提交 Issue 和 Pull Request 来帮助改进 Pillar Utils。

许可证

ISC

版本历史

v1.0.2

  • 修复枚举工具中的类型错误
  • 完善测试用例
  • 优化文档结构

v1.0.1

  • 添加日期工具集合
  • 添加正则工具集合
  • 添加数字工具集合
  • 添加对象工具集合
  • 添加枚举工具集合

v1.0.0

  • 初始版本发布
  • 基础架构搭建