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

zae-utils-tool

v1.0.0

Published

A lightweight front-end utility library for validation and common helpers.

Readme

zae-utils-tool

一个轻量、实用的前端工具库,提供常见校验、格式化、脱敏与辅助函数。

安装

npm install zae-utils-tool

使用

import Utils, { checkEmail, checkPhone, formatMoney, maskPhone, type DeviceType } from 'zae-utils-tool'

Utils.checkPhone('13800138000')
checkEmail('[email protected]')
formatMoney(1234567.8)
maskPhone('13800138000')

const device: DeviceType = Utils.getDeviceType()

工具方法

validators

checkPhone(phone: string): boolean, // 校验中国大陆手机号
checkEmail(email: string): boolean, // 校验邮箱
checkIdCard(idCard: string): boolean, // 校验中国大陆身份证号
checkUrl(url: string): boolean, // 校验 http/https 链接
checkWeChat(wechat: string): boolean, // 校验微信号
checkChineseName(name: string): boolean, // 校验中文姓名
checkPostCode(postCode: string): boolean, // 校验中国大陆邮政编码
checkEmpty(value: unknown): boolean, // 校验空值
checkNumber(value: unknown): boolean, // 校验数字
checkPasswordStrength(password: string): PasswordStrengthResult // 校验密码强度

formatters

formatPhone(phone: string, separator?: string): string, // 格式化手机号
formatMoney(amount: number | string, decimals?: number): string, // 格式化金额
formatDate(date: Date | string | number, format?: string): string, // 格式化日期
formatFileSize(size: number, decimals?: number): string // 格式化文件大小

date

formatTimestamp(timestamp: number | string, format?: string): string, // 时间戳转时间
getBeforeMonthDate(months?: number, date?: Date | string | number): Date, // 获取 n 个月前的日期
getBeforeDayDate(days?: number, date?: Date | string | number): Date, // 获取 n 天前的日期
getAfterDayDate(days?: number, date?: Date | string | number): Date, // 获取 n 天后的日期
isToday(date: Date | string | number, baseDate?: Date | string | number): boolean // 判断是否今天

array

uniqueArray<T>(array: T[], key?: keyof T | ((item: T) => unknown)): T[], // 数组去重
chunkArray<T>(array: T[], size: number): T[][], // 数组分块
flattenArray<T>(array: readonly unknown[]): T[], // 数组扁平化
groupBy<T>(array: T[], key: keyof T | ((item: T) => string | number)): Record<string, T[]> // 数组分组

string

capitalize(value: string): string, // 首字母大写
trimAll(value: string): string, // 移除全部空白字符
randomString(length?: number, chars?: string): string // 生成随机字符串

maskers

maskPhone(phone: string): string, // 脱敏手机号
maskEmail(email: string): string, // 脱敏邮箱
maskIdCard(idCard: string): string // 脱敏身份证号

helpers

debounce<T>(fn: T, delay?: number): DebouncedFunction<T>, // 防抖函数
throttle<T>(fn: T, delay?: number): ThrottledFunction<T>, // 节流函数
deepClone<T>(value: T): T, // 深拷贝
pick<T, K>(object: T, keys: K[]): Pick<T, K>, // 提取对象字段
omit<T, K>(object: T, keys: K[]): Omit<T, K>, // 排除对象字段
isEqual(source: unknown, target: unknown): boolean, // 判断两个值是否相等
sleep(delay?: number): Promise<void>, // 延迟执行
generateUUID(options?: GenerateUUIDOptions): string // 生成 UUID 或随机 ID
generateUUID() // 标准 UUID
generateUUID({ length: 8 }) // 自定义长度随机 ID
generateUUID({ length: 6, chars: 'abc', prefix: 'zae_' }) // 自定义字符集和前缀

parsers

parseUrlQuery(url: string): Record<string, string | string[]>, // 解析 URL 参数
parseQueryString(queryString: string): Record<string, string | string[]>, // 解析查询字符串
safeParseJSON<T>(jsonString: string, fallback: T): T // 安全解析 JSON

browser

isMobile(userAgent?: string): boolean, // 判断是否移动端
isWxBrowser(userAgent?: string): boolean, // 判断是否微信浏览器
getDeviceType(userAgent?: string): DeviceType // 获取设备类型

storage

存储工具分为 localStoragesessionStorageCookie。Web Storage 方法默认使用 localStorage,也可以通过最后一个参数传入 sessionStorage

setStorage(key: string, value: unknown, storage?: StorageLike | null): boolean, // 设置本地存储
getStorage<T>(key: string, fallback: T, storage?: StorageLike | null): T, // 获取本地存储
removeStorage(key: string, storage?: StorageLike | null): boolean, // 移除本地存储
clearStorage(storage?: StorageLike | null): boolean, // 清空本地存储
setCookie(name: string, value: string, options?: CookieOptions): boolean, // 设置 Cookie
getCookie(name: string, cookieString?: string): string, // 获取 Cookie
removeCookie(name: string, options?: Omit<CookieOptions, 'expires'>): boolean // 移除 Cookie
setStorage('user', { name: 'zae' }) // 默认 localStorage
setStorage('token', 'xxx', sessionStorage) // 指定 sessionStorage
setCookie('token', 'xxx', { expires: 7, path: '/' }) // 设置 Cookie

types

PasswordStrengthResult, // 密码强度校验结果类型
DebouncedFunction<T>, // 防抖函数返回类型
ThrottledFunction<T>, // 节流函数返回类型
DeviceType, // 设备类型
StorageLike, // 存储对象类型
CookieOptions, // Cookie 配置类型
GenerateUUIDOptions // UUID / 随机 ID 生成配置类型