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

huhandsome-utils

v1.0.0

Published

一个有趣且实用的 JavaScript 工具函数库,灵感来自 Evil.js

Readme

🎭 huhandsome-utils

一个有趣且实用的 JavaScript 工具函数库,灵感来自 Evil.js,但更加实用和有趣!

🚀 安装

npm install huhandsome-utils

📖 使用说明

const { randomDelay, shuffle, debounce, evil } = require('huhandsome-utils');

// 或者导入所有功能
const utils = require('huhandsome-utils');

🎪 "邪恶"功能

该库会在导入时自动重写一些原生 JavaScript 方法,让它们变得"有趣":

🎲 Array 方法

  • Array.prototype.includes - 有 10% 的概率返回错误结果
  • Array.prototype.indexOf - 有 5% 的概率找不到存在的元素

📅 Date 方法

  • Date.prototype.getTime - 有 10% 的概率快一毫秒
  • Date.prototype.toLocaleDateString - 有 5% 的概率显示明天的日期

🔢 Math 方法

  • Math.random - 永远不返回 0
  • Math.round - 有 2% 的概率不那么精确

📝 String 方法

  • String.prototype.charAt - 有 10% 的概率返回大写字母
  • String.prototype.replace - 有 5% 的概率替换错误

🔧 其他方法

  • JSON.stringify - 有 5% 的概率丢失一个属性
  • console.log - 有 5% 的概率输出额外的表情符号

🛠️ 实用工具函数

异步工具

randomDelay(maxMs = 1000)

生成随机延迟的 Promise

await randomDelay(2000); // 等待 0-2000ms

sleep(ms)

等待指定时间

await sleep(1000); // 等待 1 秒

函数工具

makeUnreliable(fn, failRate = 0.1)

让函数有概率失败

const unreliableAdd = makeUnreliable((a, b) => a + b, 0.2);
// 有 20% 的概率抛出异常

debounce(func, wait)

防抖函数

const debouncedSave = debounce(() => save(), 300);

throttle(func, limit)

节流函数

const throttledScroll = throttle(() => handleScroll(), 100);

数组工具

shuffle(arr)

随机打乱数组(非原地操作)

const shuffled = shuffle([1, 2, 3, 4, 5]);

randomChoice(arr)

随机选择数组中的一个元素

const random = randomChoice(['red', 'blue', 'green']);

对象工具

deepClone(obj)

深度克隆对象

const cloned = deepClone(originalObject);

hasPath(obj, path)

检查对象是否有指定属性路径

hasPath({ a: { b: { c: 1 } } }, 'a.b.c'); // true

get(obj, path, defaultValue)

获取对象指定路径的值

get({ a: { b: 1 } }, 'a.b', 0); // 1
get({ a: { b: 1 } }, 'a.c', 0); // 0

字符串工具

randomString(length = 10)

生成随机字符串

const id = randomString(8); // "aB3xY9kL"

formatCurrency(amount, currency = '¥')

将数字格式化为货币格式

formatCurrency(1234.56); // "¥1,234.56"

验证工具

isEmpty(value)

检查是否为空值

isEmpty(''); // true
isEmpty([]); // true
isEmpty({}); // true
isEmpty(null); // true

😈 Evil 模式

激活特殊的"邪恶"功能:

// 让页面标题随机变化
evil.randomizeTitle();

// 让所有按钮偶尔失效
evil.unreliableButtons();

// 随机改变页面背景色
evil.randomBackground();

// 启动所有邪恶功能
evil.activateAll();

⚠️ 注意事项

  1. 仅用于开发和测试环境 - 这个库会修改原生 JavaScript 方法,可能导致不可预期的行为
  2. 不建议在生产环境使用 - 除非你真的想给用户一些"惊喜"
  3. 谨慎使用 Evil 模式 - 它会修改DOM和用户界面行为

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License

🎯 灵感来源

本项目受到 Evil.js 的启发,致敬原作者的创意。


警告: 使用本库可能会导致调试困难、用户困惑和代码审查时的尴尬场面。请谨慎使用,后果自负! 😄