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

@qiaoqu/utils

v0.0.8

Published

工具集

Readme

tools

类型校验

isJSON

接收一个参数,只对 json 字符串返回 true。

isUndef

接收一个参数,未定义返回 true。

isDef

接收一个参数,定义了就返回 true。

isTrue

接收一个参数,只对布尔 true 返回 true。

isFalse

接收一个参数,只对布尔 false 返回 true。

isPrimitive

接收一个参数,只对原始类型返回 true。

isFunction

接收一个参数,只对 function 类型返回 true。

isObject

接收一个参数,只对不为 null 的 object 类型返回 true。

isPlainObject

接收一个参数,只对纯 JavaScript 对象返回 true。

isRegExp

接收一个参数,只对正则返回 true。

isPromise

接收一个参数,只对 promise 返回 true。

isDateValid

接收一个参数,只对 Date 类型返回 true。

isPhone

接收一个参数,只对正确的手机号返回 true。

类型转换

toRawType

接收一个参数,转换为原始类型。

toString

接收一个参数,转换为字符串类型。

toNumber

接收一个参数,转换为数字类型,如果转换结果为 NAN,返回 0。

toArray

接收两个参数,返回转换后的数组。

参数一(==必填==):参与转换的类数组对象,

参数二:从指定下标开始转换,默认下标 0 开始。

toObject

接收一个对象数组,合并为一个对象。

功能函数

hasOwn

接收两个参数,检查对象是否具有该属性,有该属性返回 true。

参数一(==必填==):目标对象

参数二:需要检测的 key

extend

接受两个参数,将属性混合到目标对象中,共有的属性参数二会覆盖参数一,返回混合后的对象

参数一:目标对象

参数二:参与混合的对象

cached

创建纯函数的缓存版本,接收一个函数(==必填==),返回一个缓存函数。

调用缓存函数传入要处理的参数,如果缓存中有该处理参数的处理后的结果直接返回,没有缓存则将该参数作为 key,处理结果作为值,存入缓存。

// 创建纯函数的缓存版本
function cached(fn) {
    const cache = Object.create(null);
    return function cachedFn(str) {
        const hit = cache[str];
        return hit || (cache[str] = fn(str));
    };
}
// 大写首字母字符串
const capitalize = cached((str) => {
    return str.charAt(0).toUpperCase() + str.slice(1);
});

capitalize

大写字符串首字母,接收一个参数(==必填==),返回处理后的结果。

remove

从数组中删除项,接收两个参数,返回删除项。

参数一(==必填==):目标数组

参数二:需要删除的项

looseEqual

检查两个值是否松散相等-也就是说,如果它们是普通对象,它们是否具有相同的形状?

一、如果 两个值 都是 Object 类型

​ 1、这两个值都是 Array 类型 比较这个数组的长度和每一项值是否全等;

​ 2、这两个值都是 Date 类型,比较两个日期的时间戳是否全等;

​ 3、这两个值都是 Object 类型,比较这个对象的键值是否全等;

​ 4、非以上三小种情况,返回 false;

二、如果连个值都不是对象类型,将他们都转为 String 类型比较

三、非以上两大种情况,返回 false

looseIndexOf

返回可以存在松散相等值的第一个索引。

在数组中找到(如果 value 是一个普通对象,数组必须包含相同形状的对象),如果不存在则为-1。

接受两侧参数,返回比较目标索引下标。

参数一(==必填==):目标数组。

参数二:参与查找的内容。

once

确保函数只被调用一次,接受一个参数。

rgbToHex

将 RGB 转换为十六进制,接受三个参数,分别为 r(==必填==)、g(==必填==)、b(==必填==),返回十六进制结果

randomHex

生成随机十六进制

removeDuplicates

数组去重,接收一个参数,返回去重后的结果。

random$2

生成随机数,接收一个最小值和一个最大值,生成结果包含最大最小值,默认最小值 0,最大值 10.

randomName

生成随机中文人名。

fillZero

补零,接受三个参数,返回补零后的字符串。

参数一:参与补零的数字,默认 0。

参数二:补零后的长度,默认 1。

参数三:前补还是后补,取值 0(后补)或 1(前补),默认 0。

listDataToTreeData

列表数据转 tree 状数据,接收两个参数,返回处理后的数据。

参数一:原始 list 数据。

参数二:props 配置, 指定 id、 pid、 children 对应的字段名称 {id: string, pid: string, children: string, baseVal: number | string}。

参数二:callback, 在集合中的每个项目上调用的函数。返回的值将插入到新集合中。

treeDataToListData

tree 状数据转列表数据 ,接受一个参数,返回处理后的数据。

参数一:原始 tree 状数据。

参数二:props 配置, 指定 children 对应的字段名称 {children: string}。

参数二:callback, 在集合中的每个项目上调用的函数。返回的值将插入到新集合中。

getTreeDataFirstData

获取树状数据第一条深度数据 ,接受一个参数,返回第一条深度数据。

参数一:原始 tree 状数据。

findTreeData

查找 treeData 中指定 id 数据 ,接受 5 个参数。

参数一:目标 id 参数二:原始数据 参数三:props 配置 参数四:回调函数(target: any;ind: number;arr: Array,parent: any) => void 参数五:父级数据

updateTreeData

更新 treeData 中指定 id 数据 ,接受 4 个参数。

参数一:目标 id 参数二:原始数据 参数三:props 配置 参数四:回调函数(target: any;ind: number;arr: Array) => void

getTreeDataIdAndChildIds

获取数据 id 和所有子数据 id 集合,接受 2 个参数,返回 ids 集合。

参数一:原始数据 参数二:props 配置

日期处理

dayOfYear

接收一个日期,查询该日期在当年是第几天,默认当前日期,返回指定日期或者当前日期在当前是第几天。

dayDif

接收两个日期,计算两个日期之间相差的天数,默认当前日期,返回两个日期之间相差的天数。

getWeekday

获取工作日,接收两个参数,返回指定日期或者当前日期的工作日。

参数一:查询的日期

参数二:返回值的前缀,默认为“星期”,表示星期 X。

getDateInfo

获取日期信息,接收两个参数,返回包含年月日周时分秒和格式化后的日期。

参数一:查询的日期,默认当前日期

参数二:返回结果之中“dt”属性的格式化格式,默认为“YYYY-MM-DD hh:mm:ss”。

formatDate

格式化日期,接收两个参数,返回格式化后的日期。

参数一:参与格式化的日期,默认当前日期

参数二:格式化的格式,默认为“YYYY-MM-DD hh:mm:ss”。