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

common-utils-y

v0.0.22

Published

my common utils lib

Readme

my common utils lib

安装使用

npm install common-utils-y
import { isBoolean, isEmpty, enterFullscreen } from "common-utils-y";

推荐使用 typescript

默认使用 lib 目录下入口,包含浏览器方法

不需要 browser 目录方法可以使用lib-node目录

import { isBoolean, isEmpty } from "common-utils-y/lib-node";

代码提升方便使用

已有的方法

| 目录 | 方法 | | -------- | --------------------------------------------------------------------- | | array | 数组的常用方法,如 uniqueArray、getUniqueArray | | number | 数字处理, 如 getRandomInt | | string | 字符串处理,如 capitalizeFirstLetter、toCamelStyle | | object | 对象方法,如 deepCopy | | function | 函数,如 debounce、 throttle | | date | 日期方法,如 formatDate | | types | 数据类型判断,如 isBigInt、isBoolean | | browser | 浏览器 api, 如 enterFullscreen、exitFullscreen、getFullscreenElement |

数组(array)

数组相关方法

| 方法 | 说明 | | -------------- | -------------------------------------------------------------- | | uniqueArray | 简单数据数组去重方法,适用于数字、字符串等类型数组 | | getUniqueArray | 根据 key 属性去重对象数组 | | findPathInTree | 查找树形数据中从根节点到目标节点的完整路径,未找到则返回空数组 |

数字(number)

数字相关方法

| 方法 | 说明 | | ------------ | ------------------------------ | | getRandomInt | 获取两个数字间的随机整数值 | | addCommas | 数字添加千分符,小数部分不处理 | | add | 多个数字相加,包含精度处理 | | subtract | 多个数字相减,包含精度处理 | | multiply | 多个数字相乘,包含精度处理 | | divide | 多个数字相除,包含精度处理 |

字符串(string)

字符串相关方法

| 方法 | 说明 | | --------------------- | ---------------------- | | capitalizeFirstLetter | 字符串首字母大写 | | toCamelStyle | 将字符串转为小驼峰写法 | | escapeHTML | 将字符串 HTML 转义 | | escapeCSS | 将字符串 css 转义 | | escapeJS | 将字符串 js 转义 |

对象(object)

对象相关方法

| 方法 | 说明 | | -------- | -------------------------------------------------------------------- | | deepCopy | 深拷贝函数,支持处理日期、数组、正则表达式、Map、Set,函数则直接返回 |

函数(function)

函数相关方法

| 方法 | 说明 | | -------- | -------------------------------- | | debounce | 防抖函数,支持取消执行 | | throttle | 节流函数,支持立即执行和尾部执行 |

日期(date)

日期相关方法

| 方法 | 说明 | | ----------- | ------------------------------ | | isDate | 判断是否日期对象 | | isValidDate | 判断是否为合法日期对象 | | formatDate | 将日期对象格式化为自定义字符串 |

日期格式化支持的符号

| 符合 | 说明 | 示例 | | ---- | --------------------------- | ---------------------------------------- | | yyyy | 4 位年份 | 2025 | | yy | 2 位年份 | 25 | | MM | 2 位月份(补零) | 01-12 | | M | 月份(不补零) | 1-12 | | dd | 2 位日期(补零) | 01-31 | | d | 日期(不补零) | 1-31 | | HH | 2 位小时(24 小时制,补零) | 00-23 | | H | 小时(24 小时制,不补零) | 0-23 | | hh | 2 位小时(12 小时制,补零) | 01-12 | | h | 小时(12 小时制,不补零) | 1-12 | | mm | 2 位分钟(补零) | 00-59 | | m | 分钟(不补零) | 0-59 | | ss | 2 位秒(补零) | 00-59 | | s | 秒(不补零) | 0-59 | | a | 上午/下午 | 上午/下午 | | Q | 季度 | 1-4 | | w | 星期 | '日', '一', '二', '三', '四', '五', '六' |

类型(type)

类型相关方法

| 方法 | 说明 | | ---------- | -------------------------------- | | isBoolean | 判断参数是否为布尔值 | | isNumber | 判断参数是否为数字 | | isString | 判断参数是否为字符串 | | isFunction | 判断参数是否为函数 | | isBigInt | 判断参数是否为 bigInt | | isArray | 判断参数是否为数组 | | isEmpty | 判断参数是否为 null 或 undefined |

浏览器(browser)

浏览器相关方法

| 方法 | 说明 | | -------------------- | ------------------------------ | | enterFullscreen | 请求进入全屏 | | exitFullscreen | 请求退出全屏 | | getFullscreenElement | 获取当前全屏元素 | | addResizeObserve | 监听元素尺寸变化并执行回调函数 | | removeResizeObserve | 取消监听尺寸的回调函数 |

规划

后续补充一些常用的基础方法,方便不同项目开发。

包括不同数据类型的常用工具封装,以及不同浏览器兼容性 api 的进一步封装。

欢迎各位大佬帮助补充、纠偏。。。