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

@pengmeng/ui-utils

v0.0.2

Published

UI 组件库公共工具函数

Downloads

230

Readme

@pengmeng/ui-utils

UI 组件库公共工具函数,可独立使用,支持 Tree-shaking。

安装

pnpm add @pengmeng/ui-utils

按需引入

// 只引入需要的函数,减少打包体积
import { formatMoney, isPhone } from '@pengmeng/ui-utils';

// 或者从具体模块引入
import { formatMoney } from '@pengmeng/ui-utils/es/format';
import { isPhone } from '@pengmeng/ui-utils/es/validate';

API 文档

DOM 工具 (dom.ts)

| 函数 | 说明 | |------|------| | isBrowser | 判断是否在浏览器环境 | | getScrollContainer(el) | 获取滚动容器 | | getOffsetTop(el) | 获取元素距离文档顶部的距离 | | isInViewport(el) | 判断元素是否在视口内 | | copyToClipboard(text) | 复制文本到剪贴板 |

格式化工具 (format.ts)

| 函数 | 说明 | |------|------| | formatNumber(num, decimals) | 格式化数字(千分位) | | formatMoney(amount, decimals) | 格式化金额 | | formatPercent(num, decimals) | 格式化百分比 | | formatFileSize(bytes) | 格式化文件大小 | | truncate(str, length, suffix) | 截断字符串 | | maskPhone(phone) | 手机号脱敏 | | maskIdCard(idCard) | 身份证号脱敏 |

校验工具 (validate.ts)

| 函数 | 说明 | |------|------| | isPhone(value) | 校验手机号 | | isEmail(value) | 校验邮箱 | | isIdCard(value) | 校验身份证号 | | isUrl(value) | 校验 URL | | isEmpty(value) | 校验是否为空 | | isCreditCode(value) | 校验统一社会信用代码 | | isPositiveInteger(value) | 校验正整数 | | isChinese(value) | 校验中文字符 |

类名工具 (classnames.ts)

| 函数 | 说明 | |------|------| | classnames(...args) | 合并类名 | | createBEM(block) | 创建 BEM 类名生成器 |

使用示例

import { formatMoney, maskPhone, classnames, createBEM } from '@pengmeng/ui-utils';

// 格式化金额
formatMoney(1234567.89); // => '¥1,234,567.89'

// 手机号脱敏
maskPhone('13812345678'); // => '138****5678'

// 合并类名
classnames('foo', { bar: true, baz: false }); // => 'foo bar'

// BEM 类名
const bem = createBEM('button');
bem(); // => 'button'
bem('icon'); // => 'button__icon'
bem({ active: true }); // => 'button button--active'