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

@ruanmingze/happykit

v1.0.3

Published

HappyKit(快乐工具箱)- 一个Node.js实用工具库

Downloads

34

Readme

HappyKit(快乐工具箱)

HappyKit是一个Node.js实用工具库,提供了丰富的工具函数,涵盖字符串处理、数组操作、日期格式化、数据验证、文件处理、网络请求、数学计算等常用功能领域。

许可证

本项目采用GPL-2.0-Only许可证进行许可。

安装

使用npm

npm install @ruanmingze/happykit

使用yarn

yarn add @ruanmingze/happykit

使用pnpm

pnpm add @ruanmingze/happykit

版本说明

HappyKit提供两个版本:

| 版本 | 文件名 | 适用环境 | 说明 | |------|--------|----------|------| | Node.js版 | happykit.js | Node.js、Electron | 完整功能,包含文件系统、网络请求等Node.js模块 | | 浏览器版 | happykit.browser.js | 浏览器、前端项目 | 纯前端功能,不包含Node.js特有模块 |

使用方法

Node.js环境

const HappyKit = require('@ruanmingze/happykit');

// 使用示例
console.log(HappyKit.capitalize('hello')); // 'Hello'

前端环境(CDN)

<script src="https://lib.ruanmgjx.dpdns.org/happykit.browser.js"></script>
<script>
  // 使用示例
  console.log(HappyKit.capitalize('hello')); // 'Hello'
</script>

前端环境(npm + 打包工具)

import * as HappyKit from '@ruanmingze/happykit';

// 使用示例
console.log(HappyKit.capitalize('hello')); // 'Hello'

API概览

字符串处理

  • format(str, ...args) - 格式化字符串
  • capitalize(str) - 首字母大写
  • camelToKebab(str) - 驼峰转连字符
  • kebabToCamel(str) - 连字符转驼峰
  • trim(str) - 移除字符串首尾空格
  • repeat(str, times) - 重复字符串
  • truncate(str, length, ellipsis) - 截取字符串
  • randomString(length) - 生成随机字符串

数组操作

  • unique(arr) - 数组去重
  • sort(arr, order) - 数组排序
  • filter(arr, callback) - 数组筛选
  • map(arr, callback) - 数组映射
  • reduce(arr, callback, initialValue) - 数组归约
  • merge(...arrs) - 数组合并
  • chunk(arr, size) - 数组分割
  • shuffle(arr) - 数组随机排序

日期处理

  • formatDate(date, format) - 格式化日期
  • getTimeDiff(date1, date2, unit) - 计算时间差
  • getCurrentDate() - 获取当前日期
  • addDays(date, amount, unit) - 日期相加
  • isToday(date) - 判断是否是今天
  • getDaysInMonth(year, month) - 获取月份的天数
  • isLeapYear(year) - 判断是否是闰年

数据验证

  • validateEmail(email) - 验证邮箱格式
  • validatePhone(phone) - 验证手机号格式
  • validateURL(url) - 验证URL格式
  • validateIdCard(idCard) - 验证身份证号格式
  • validatePassword(password) - 验证密码强度
  • isEmpty(value) - 验证是否为空
  • isNumber(value) - 验证是否是数字
  • isString(value) - 验证是否是字符串

文件处理

  • readFile(filePath, encoding) - 读取文件内容
  • writeFile(filePath, content, encoding) - 写入文件内容
  • fileExists(filePath) - 检查文件是否存在
  • createDirectory(dirPath, recursive) - 创建目录
  • listDirectory(dirPath) - 列出目录内容
  • joinPath(...paths) - 连接路径
  • getFileExtension(filePath) - 获取文件扩展名
  • getFileName(filePath, includeExtension) - 获取文件名

网络请求

  • sendRequest(url, options, data) - 发送HTTP/HTTPS请求
  • get(url, options) - 发送GET请求
  • post(url, data, options) - 发送POST请求
  • put(url, data, options) - 发送PUT请求
  • del(url, options) - 发送DELETE请求
  • downloadFile(url, destPath) - 下载文件

数学计算

  • random(min, max) - 生成随机数
  • randomInt(min, max) - 生成随机整数
  • abs(num) - 计算绝对值
  • sqrt(num) - 计算平方根
  • square(num) - 计算平方
  • cube(num) - 计算立方
  • average(arr) - 计算平均值
  • sum(arr) - 计算数组总和
  • max(arr) - 计算数组最大值
  • min(arr) - 计算数组最小值

顶部标题栏(Electron应用)

  • createTLBar(options) - 创建非绝对定位的顶部标题栏
  • updateTitleBarTitle(titleBar, title) - 更新标题栏标题

示例代码

创建顶部标题栏

const { createTLBar } = require('happykit');

// 创建标题栏
const titleBar = createTLBar({
  title: '我的应用',
  backgroundColor: '#2c3e50',
  textColor: '#ffffff',
  height: 60,
  onMinimize: () => {
    console.log('最小化');
  },
  onMaximize: () => {
    console.log('最大化');
  },
  onClose: () => {
    console.log('关闭');
  }
});

// 添加到页面
document.body.appendChild(titleBar);

字符串处理

const { format, capitalize, truncate } = require('happykit');

console.log(format('Hello {0}, welcome to {1}!', 'John', 'HappyKit')); // 'Hello John, welcome to HappyKit!'
console.log(capitalize('hello world')); // 'Hello world'
console.log(truncate('This is a long string', 10)); // 'This is a...'

数组操作

const { unique, sort, chunk } = require('happykit');

console.log(unique([1, 2, 2, 3, 4, 4, 5])); // [1, 2, 3, 4, 5]
console.log(sort([3, 1, 4, 1, 5, 9], 'desc')); // [9, 5, 4, 3, 1, 1]
console.log(chunk([1, 2, 3, 4, 5, 6], 2)); // [[1, 2], [3, 4], [5, 6]]

日期处理

const { formatDate, getTimeDiff } = require('happykit');

const date = new Date();
console.log(formatDate(date, 'YYYY-MM-DD HH:mm:ss')); // '2023-10-01 12:34:56'

const date1 = new Date('2023-10-01');
const date2 = new Date('2023-10-05');
console.log(getTimeDiff(date1, date2, 'days')); // 4

数据验证

const { validateEmail, validatePhone, validateURL } = require('happykit');

console.log(validateEmail('[email protected]')); // true
console.log(validatePhone('13812345678')); // true
console.log(validateURL('https://www.example.com')); // true

构建

开发环境

npm run dev

生产环境(Node.js版本)

npm run build

浏览器版本

npm run build:browser

构建所有版本

npm run build:all

测试

npm run test

文档

生成API文档:

npm run doc

贡献

欢迎提交Issue和Pull Request!

联系方式

如有问题或建议,请通过Issue与我们联系。