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

mahmud-js-tools

v1.0.12

Published

一个简单而实用的JavaScript工具库,包含多种常用的工具函数。

Readme

📜🛠️mahmud-js-tools🛠️📜

mahmud-js-tools 是一个简单而实用的 JavaScript 工具库,包含多种常用的工具函数,如🎯深拷贝对象、🎯防抖函数、🎯比较对象、🎯节流函数、🎯生成随机数、🎯格式化时间、🎯验证 URL、🎯数组去重、🎯首字母大写、🎯驼峰命名转换、🎯打乱数组顺序和🎯异步延迟等。

English | 简体中文

特性

  • 🚀 高性能虚拟滚动 - 轻松渲染百万级数据,保持流畅的滚动体验
  • 🔄 动态高度适配 - 自动处理超大数据集,防止DOM高度溢出
  • 🎯 简单易用API - 直观的接口设计,快速集成到任何项目
  • 📦 轻量级 - 无依赖,体积小,加载快
  • 🔧 高度可定制 - 支持自定义渲染函数,满足各种UI需求

目录结构

. ├── dist │ ├── index.js │ └── index.js.map ├── src │ ├── index.js │ └── test.js ├── .gitignore ├── LICENSE ├── README.md └── package.json

功能列表

| 函数名 | 描述 | 示例 | | ------------ | ------------------------ | -------------------------- | | deepClone | 深拷贝对象 | deepClone({a: 1}) | | cloneArray | 深拷贝数组 | cloneArray([1, {b: 2}]) | | debounce | 防抖函数 | debounce(fn, 300) | | throttle | 节流函数 | throttle(fn, 300) | | isEqual | 比较两个对象是否相等 | isEqual(obj1, obj2) | | random | 生成指定范围的随机数 | random(1, 10) | | formatTime | 格式化时间戳为可读字符串 | formatTime(1620000000) | | isUrl | 验证 URL 是否有效 | isUrl('https://...') | | unique | 数组去重 | unique([1, 2, 2, 3]) | | capitalize | 将字符串首字母大写 | capitalize('hello') | | camelCase | 将字符串转换为驼峰命名法 | camelCase('hello-world') | | shuffle | 打乱数组顺序 | shuffle([1, 2, 3, 4]) | | sleep | 异步延迟(Promise) | await sleep(1000) |

📜安装

您可以使用 npm 来安装这个库:

npm install mahmud-js-tools

🛠️CDN

<!-- 生产环境(压缩版) -->
<!-- <script src="https://unpkg.com/[email protected]/dist/index.min.js"></script> -->
     <script src="https://unpkg.com/[email protected]/dist/index.js"></script>


<!-- 开发环境(未压缩) -->
<!-- <script src="https://unpkg.com/[email protected]/dist/index.js"></script> -->
     <script src="https://unpkg.com/[email protected]/dist/index.js"></script>

🚀使用

alt text alt text alt text alt text alt text alt text alt text

deepClone 用于深拷贝对象。

const { deepClone } = require('mahmud-js-tools');

const obj = { a: 1, b: { c: 2 } };
const cloned = deepClone(obj);
console.log(cloned); // { a: 1, b: { c: 2 } }
console.log(cloned === obj); // false

cloneArray 用于深拷贝数组。

const { cloneArray } = require("mahmud-js-tools");

const arr = [1, { b: 2 }];
const clonedArr = cloneArray(arr);
console.log(clonedArr); // [1, { b: 2 }]
console.log(clonedArr === arr); // false

debounce 用于防抖函数。

const { debounce } = require("mahmud-js-tools");

const mockFn = jest.fn();
const debouncedFn = debounce(mockFn, 100);

debouncedFn();
setTimeout(() => {
  console.log(mockFn.mock.calls.length); // 1
}, 200);

throttle 用于节流函数。

const { throttle } = require("mahmud-js-tools");

const mockFn = jest.fn();
const throttledFn = throttle(mockFn, 100);

throttledFn();
throttledFn();

setTimeout(() => {
  console.log(mockFn.mock.calls.length); // 1
}, 200);

isEqual 用于比较两个对象是否相等。

const { isEqual } = require("mahmud-js-tools");

const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 2 } };
const obj3 = { a: 1, b: { c: 3 } };

console.log(isEqual(obj1, obj2)); // true
console.log(isEqual(obj1, obj3)); // false

random 用于生成指定范围的随机数。

const { random } = require("mahmud-js-tools");

console.log(random(1, 10)); // 随机数在 1 到 10 之间

formatTime 用于格式化时间戳为可读字符串。

const { formatTime } = require("mahmud-js-tools");

console.log(formatTime(1620000000000)); // 2021-05-03 00:00:00

isUrl 用于验证 URL 是否有效。

const { isUrl } = require("mahmud-js-tools");

console.log(isUrl("https://google.com")); // true
console.log(isUrl("not-a-url")); // false

unique 用于数组去重。

const { unique } = require("mahmud-js-tools");

console.log(unique([1, 2, 2, 3])); // [1, 2, 3]

capitalize 用于将字符串首字母大写。

const { capitalize } = require("mahmud-js-tools");

console.log(capitalize("hello")); // Hello

camelCase 用于将字符串转换为驼峰命名法。

const { camelCase } = require("mahmud-js-tools");

console.log(camelCase("hello-world")); // helloWorld

shuffle 用于打乱数组顺序。

const { shuffle } = require("mahmud-js-tools");

const arr = [1, 2, 3, 4];
const shuffledArr = shuffle(arr);
console.log(shuffledArr); // 随机打乱后的数组

sleep 用于异步延迟。

const { sleep } = require("mahmud-js-tools");

async function testSleep() {
  const start = Date.now();
  await sleep(1000);
  const end = Date.now();
  console.log(end - start); // 1000 或更接近的值
}

testSleep();

🧪单元测试

项目使用 Jest 进行完整测试,运行以下命令执行测试:

npm run test

🤝贡献指南

欢迎对这个项目进行贡献!请遵循以下步骤:

  1. Fork 本仓库。
  2. 创建新分支 (git checkout -b feature/your-feature)。
  3. 提交更改 (git commit -m 'Add some feature')。
  4. 推送分支 (git push origin feature/your-feature)。
  5. 提交 Pull Request。
  • 🎯 欢迎访问我的技术博客:- © https://gitee.com/mahmudtjcu
  • 🎯 欢迎访问我的Gitee:- © https://www.cnblogs.com/mahmud

📜许可证

本项目使用 MIT 许可证