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-utils-tools2

v1.0.2

Published

一个功能丰富的前端工具库,用于处理日期、文字、数字和数据格式 处理的实用函数。

Readme

前端工具库 | mahmud-utils-tools2

📑 目录

目录结构

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

✨ 功能特点

  • 📅 日期处理:格式化日期、日期计算、相对时间等
  • 📝 文本处理:文本截断、命名格式转换、敏感信息掩码等
  • 🔢 数字处理:格式化数字、货币转换、精确计算等
  • 📊 数据处理:深拷贝、对象扁平化、数组处理等

🛠️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/data/index.js"></script>
     <script src="https://unpkg.com/[email protected]/dist/date/index.js"></script>
     <script src="https://unpkg.com/[email protected]/dist/number/index.js"></script>
     <script src="https://unpkg.com/[email protected]/dist/text/index.js"></script>

📦 安装

# npm
npm install mahmud-utils-tools2

# yarn
npm install mahmud-utils-tools2

# pnpmnpm install mahmud-utils-tools2

🔨 使用示例

📅 日期处理

import { formatDate, getRelativeTimeDescription } from 'mahmud-utils-tools2';

// 格式化日期
console.log(formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss')); // 2023-04-01 14:30:45

// 获取相对时间描述
console.log(getRelativeTimeDescription(new Date(Date.now() - 3600000))); // 1小时前

📝 文本处理

import { truncate, maskString, toCamelCase } from 'mahmud-utils-tools2';

// 截断文本
console.log(truncate('这是一段很长的文本内容', 6)); // 这是一段很...

// 掩码处理敏感信息
console.log(maskString('13812345678')); // 138****5678

// 命名格式转换
console.log(toCamelCase('user_name')); // userName

🔢 数字处理

import { formatNumber, formatCurrency, numberToChinese, preciseCalc } from 'mahmud-utils-tools2';

// 格式化数字
console.log(formatNumber(12345.6789)); // 12,345.68

// 格式化货币
console.log(formatCurrency(12345.6789)); // ¥12,345.68

// 数字转中文大写金额
console.log(numberToChinese(12345.67)); // 壹万贰仟叁佰肆拾伍元陆角柒分

// 精确计算
console.log(preciseCalc.add(0.1, 0.2)); // 0.3

📊 数据处理

import { deepClone, getPropertyByPath, sortArrayByKey } from 'mahmud-utils-tools2';

// 深拷贝对象
const obj = { user: { name: '张三', age: 30 } };
const cloned = deepClone(obj);

// 获取嵌套属性
console.log(getPropertyByPath(obj, 'user.name')); // 张三

// 按属性排序数组
const users = [{ name: '张三', age: 30 }, { name: '李四', age: 25 }];
console.log(sortArrayByKey(users, 'age')); // [{ name: '李四', age: 25 }, { name: '张三', age: 30 }]

📚 API 文档

📅 日期工具 (date)

| 函数名 | 描述 | | ------ | ---- | | formatDate(date, format) | 将日期格式化为指定格式的字符串 | | startOfDay(date) | 获取日期的开始时间(00:00:00) | | endOfDay(date) | 获取日期的结束时间(23:59:59.999) | | differenceInDays(dateLeft, dateRight) | 计算两个日期之间的天数差异 | | addTime(date, amount, unit) | 向日期添加指定时间 | | isDateInRange(date, startDate, endDate) | 检查日期是否在指定范围内 | | isWeekday(date) | 检查日期是否是工作日(周一至周五) | | getRelativeTimeDescription(date, baseDate) | 获取相对时间描述 |

📝 文本工具 (text)

| 函数名 | 描述 | | ------ | ---- | | truncate(text, maxLength, ellipsis) | 截断文本到指定长度 | | toCamelCase(text) | 转换字符串为驼峰命名 | | toPascalCase(text) | 转换字符串为帕斯卡命名 | | toSnakeCase(text) | 转换字符串为下划线命名 | | toKebabCase(text) | 转换字符串为中划线命名 | | capitalize(text) | 首字母大写 | | strLength(text, countType) | 计算字符串长度(支持中文等双字节字符) | | stripHtml(html) | 移除字符串中的HTML标签 | | isEmpty(text) | 判断字符串是否为空 | | maskString(text, startVisible, endVisible, mask) | 敏感信息掩码处理 |

🔢 数字工具 (number)

| 函数名 | 描述 | | ------ | ---- | | formatNumber(num, options) | 格式化数字为千分位分隔的字符串 | | unFormatNumber(num) | 将千分位分隔的字符串转换为数字 | | formatCurrency(amount, options) | 格式化金额为货币字符串 | | numberToChinese(num) | 将数字转换为中文大写金额 | | abbreviateNumber(num, digits) | 将数字转换为指定数量级的简写 | | randomNumber(min, max, isInteger) | 生成指定范围内的随机数 | | clamp(num, min, max) | 将数字限制在指定范围内 |

preciseCalc: 精确的浮点数运算对象

| 方法名 | 描述 | | ------ | ---- | | add(a, b) | 精确加法 | | subtract(a, b) | 精确减法 | | multiply(a, b) | 精确乘法 | | divide(a, b) | 精确除法 | | round(a, decimals) | 精确四舍五入 |

📊 数据工具 (data)

| 函数名 | 描述 | | ------ | ---- | | deepClone(obj) | 深拷贝对象 | | deepEqual(obj1, obj2) | 深度比较两个对象是否相等 | | flattenObject(obj, prefix) | 对象扁平化 | | getPropertyByPath(obj, path, defaultValue) | 获取对象的嵌套属性值 | | setPropertyByPath(obj, path, value) | 设置对象的嵌套属性值 | | removeFromArray(array, predicate) | 从数组中移除指定元素 | | sortArrayByKey(array, key, order) | 根据指定属性对对象数组进行排序 | | groupArrayByKey(array, key) | 根据指定属性对对象数组进行分组 | | uniqueArray(array, key) | 数组去重 | | range(start, end, step) | 生成指定范围内的数字数组 | | safeParseJSON(jsonString, defaultValue) | 安全地解析JSON字符串 | | getStorageItem(key, defaultValue) | 安全地获取缓存数据 | | setStorageItem(key, value) | 安全地存储数据到本地缓存 |

🤝贡献指南

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

  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 许可证