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

@muyianking/utils

v0.2.1

Published

通用工具函数库:通用判断与转换、DOM 与单位换算、文件处理、树结构转换、表单校验、颜色处理、localStorage 缓存与 ECharts 初始化

Readme

特性

  • 纯 ESM:只提供 ES Module 产物,sideEffects: false,按需引入即可被 tree-shaking
  • 自带类型:类型声明与源码同源,moduleResolutionbundler / node16 / nodenext 均可正确解析
  • 模块化:通用判断与转换、DOM 与单位换算、文件处理、树结构转换、常用校验(整数/端口/邮箱/手机号/IP/经纬度/身份证)、颜色处理、带过期时间的 localStorage 缓存、ECharts 初始化

安装

# npm
npm i @muyianking/utils

# yarn
yarn add @muyianking/utils

# pnpm
pnpm i @muyianking/utils

使用

import {
  echartsUtil,
  flatTree,
  guid,
  isEmail,
  isIdNum,
  isMobilePhone,
  isTruth,
  jsonparse,
  makeTree,
  mix,
  storage,
  treeToTable,
} from '@muyianking/utils'

// 通用工具
guid() // 'aB3dEfGhIjKlMnOp'
isTruth('false') // false
jsonparse('{"a":1}', {}) // { a: 1 }

// 树结构
flatTree(treeData) // 树 → 一维数组
makeTree(list, { props: { label: 'name', value: 'id', parent: 'parentId' } }) // 一维数组 → 树
treeToTable(treeData) // 树 → 带 rowspan/colspan 的表格行,子节点字段名为 next

// 校验(纯函数,返回 boolean)
isIdNum('11010519491231002X') // true
isEmail('[email protected]') // true
isMobilePhone('13800138000') // true

// 颜色
mix('#ff0000', '#ffffff', 0.5) // '#ff8080',支持 #abc 与 #aabbcc

// 缓存(键名原样存入 localStorage,默认 7 天过期)
storage.set('token', { value: 'x' }, { expire: 1 })
const token = storage.get<{ value: string }>('token')
storage.remove('token')

文档

完整的模块说明、参数表与示例见 doc/index.md

| 模块 | 说明 | | -------------------------------------------- | ------------------------------------- | | color | 16 进制与 rgb 互转、亮暗判断、混色 | | common | 通用判断与转换 | | dom | 全屏、溢出判断、mm/px/pt 单位换算 | | echarts.util | ECharts 初始化与地图注册 | | file | 文件类型判断、下载、Blob 与 JSON 互转 | | storage | 带过期时间的 localStorage 缓存 | | tree.flatTree | 树扁平化 | | tree.maketree | 一维数组构建树 | | tree.to.table | 树转表格合并单元格数据 | | validator | 常用校验 |

部分模块(domfilestorageecharts.util)依赖浏览器环境,在 SSR / Node 中需要做环境判断后再调用。

开发

pnpm install
pnpm test        # 跑一次测试
pnpm test:watch  # 监听模式
pnpm coverage    # 覆盖率
pnpm typecheck   # 源码与测试的类型检查
pnpm lint        # ESLint(含文档与 CI 配置)
pnpm build       # 产物输出到 dist/

Contributors