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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@whitesev/utils

v2.9.10

Published

一个常用的工具库

Downloads

680

Readme

安装

  • 最新版本:npm version
npm install @whitesev/utils
// 或者
pnpm add @whitesev/utils

使用文档

  • Utils.isNull 判断对象是否为空
Utils.isNull(0);
结果:false

Utils.isNull("");
结果:false

Utils.isNull(" ");
结果:false

Utils.isNull(undefined);
结果:false
  • Utils.assign 代替 Object.assign
Utils.assign({1:1},{1:2,2:3})
结果:{1:2}
  • Utils.waitNode 等待元素出现在页面中,非使用setInterval实现,性能损耗较少
/* 等待a元素出现,返回Promise对象,在then中或使用await获取结果,统一返回数组格式的元素,如[...a] */
Utils.waitNode("a").then((element) => {
  console.log(element);
});

/* 同时满足多个选择器的结果,都满足了才会触发回调 */
let moreDOM = await Utils.waitNode("#page", "a[href]");
console.log(moreDOM);
  • Utils.isVisible 判断元素是否是可见的
  • Utils.isPhone 判断当前的User-Agent是否是移动端
  • Utils.toJSON 代替JSON.parse,满足更多格式的转换对象
Utils.toJSON("{123:123}");
结果:{123:123}
  • Utils.Httpx 代替油猴的GM_xmlhttpRequest,统一管理请求状态
let httpx = new Utils.Httpx();
/* 修改配置 */
httpx.config({
  timeout: 5000,
  onabort: function () {
    console.log("请求取消");
  },
  ontimeout: function () {
    console.log("请求超时");
  },
  onerror: function (response) {
    console.log("httpx-onerror 请求异常");
    console.log(response);
  },
});
/* 发送post请求 */
let postResp = await httpx.post({
  url: url,
  data: JSON.stringify({
    test: 1,
  }),
});
  • Utils.GM_Menu 代替油猴的GM_registerMenuCommandGM_unregisterMenuCommand,管理油猴菜单
let GM_Menu = new Utils.GM_Menu({
data: [
    {
    menu_key: "menu_key",
    text: "测试按钮",
    enable: true,
    accessKey: "a",
    autoClose: false,
    showText(text, enable) {
        return "[" + (enable ? "√" : "×") + "]" + text;
    },
    callback(data) {
        console.log("点击菜单,值修改为", data.enable);
    },
    },
],
autoReload: false,
GM_getValue,
GM_setValue,
GM_registerMenuCommand,
GM_unregisterMenuCommand,
});


// 获取某个菜单项的值
GM_Menu.get("menu_key");
> true

// 获取某个菜单项的开启/关闭后显示的文本
GM_Menu.getShowTextValue("menu_key");
> √测试按钮

// 添加键为menu_key2的菜单项
GM_Menu.add({
key:"menu_key2",
text: "测试按钮2",
enable: false,
showText(text,enable){
    return "[" + (enable ? "√" : "×") + "]" + text;
},
callback(data){
    console.log("点击菜单,值修改为",data.enable);
}
});
// 使用数组的方式添加多个菜单,如menu_key3、menu_key4
GM_Menu.add([
{
    key:"menu_key3",
    text: "测试按钮3",
    enable: false,
    showText(text,enable){
    return "[" + (enable ? "√" : "×") + "]" + text;
    },
    callback(data){
    console.log("点击菜单,值修改为",data.enable);
    }
},
{
    key:"menu_key4",
    text: "测试按钮4",
    enable: false,
    showText(text,enable){
    return "[" + (enable ? "√" : "×") + "]" + text;
    },
    callback(data){
    console.log("点击菜单,值修改为",data.enable);
    }
}
]);

// 更新键为menu_key的显示文字和点击回调
GM_Menu.update({
menu_key:{
    text: "更新后的测试按钮",
    enable: true,
    showText(text,enable){
    return "[" + (enable ? "√" : "×") + "]" + text;
    },
    callback(data){
    console.log("点击菜单更新后的测试按钮,新值修改为",data.enable);
    }
}
});

// 删除键为menu_key的菜单
GM_Menu.delete("menu_key");

等...API 请看文档