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

cmpt-huitu-utils

v2.0.2

Published

慧图前端通用工具库,包含常用的工具函数、正则校验、缓存管理、权限控制等功能。

Readme

@huitu/utils

慧图前端通用工具库,包含常用的工具函数、正则校验、缓存管理、权限控制等功能。

📦 安装

在 Monorepo 项目中,该包通常已经作为依赖安装。

🛠 核心模块

1. 缓存管理 (cache)

统一封装 localStoragesessionStorage 操作,支持 JSON 对象直接存储。

import { cache } from 'cmpt-huitu-utils'

// SessionStorage 操作
cache.session.set('key', 'value')
const user = cache.session.getJSON('userInfo')

// LocalStorage 操作
cache.local.set('token', 'xxx')
cache.local.setJSON('settings', { theme: 'dark' })

2. 消息提示 (modal)

统一封装 Element Plus 的消息反馈组件,简化调用方式。

import { modal } from 'cmpt-huitu-utils'

// 消息提示
modal.msgSuccess('操作成功')
modal.msgError('操作失败')

// 确认框
modal.confirm('确认删除吗?').then(() => {
  // ...
})

// Loading
modal.loading('加载中...')
modal.closeLoading()

3. 通用工具函数 (utils)

包含大量常用的业务工具函数。

import { 
  generateUUID, 
  treeToArray, 
  dateFormatFn,
  deepClone 
} from 'cmpt-huitu-utils'

// 生成 UUID
const id = generateUUID()

// 树形转数组
const list = treeToArray(treeData)

// 时间格式化
const timeStr = dateFormatFn(timestamp)

// 深拷贝
const newObj = deepClone(obj)

4. 正则校验 (regular/validate)

常用的表单校验正则表达式函数。

import { 
  isPhone, 
  isEmail, 
  isExternal 
} from 'cmpt-huitu-utils'

if (isPhone('13800138000')) {
  // ...
}

5. 认证与权限 (auth)

封装 Token 和用户信息的存取操作。

import { 
  getToken, 
  setToken, 
  getUserInfo 
} from 'cmpt-huitu-utils'

const token = getToken()
const userInfo = getUserInfo()

📚 完整 API 列表

Utils (通用工具)

  • generateUUID: 生成 UUID
  • treeToArray: 树形结构平铺
  • getFlatArr: 多维数组转一维
  • copyToClipboard: 复制到剪贴板
  • randomData: 生成随机数
  • numberToCurrencyNo: 数字转千分位
  • sizeFormat: 文件大小格式化
  • downloadFileForm: 表单方式下载文件
  • getBigMD5: 获取大文件 MD5

Regular (正则校验)

  • isPhone: 手机号校验
  • isEmail: 邮箱校验
  • isExternal: 是否为外链
  • longitude: 经度校验
  • latitude: 纬度校验
  • specialCharacter: 特殊字符校验

Modal (交互反馈)

  • msg, msgSuccess, msgError, msgWarning
  • alert, alertSuccess, alertError
  • notify, notifySuccess, notifyError
  • confirm, prompt
  • loading, closeLoading

Cache (缓存)

  • session: set, get, setJSON, getJSON, remove
  • local: set, get, setJSON, getJSON, remove