1.0.2 • Published 5 months ago

nnnn-demo-2025 v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Utils Demo

一个实用的 JavaScript/TypeScript 工具库,提供精确的数学计算和常用的工具函数。

特性

  • 🔢 精确数学计算 - 使用 decimal.js 确保浮点数运算的精确性
  • 🔄 函数工具 - 提供防抖(debounce)和节流(throttle)等常用函数
  • 类型检查 - 提供类型判断工具函数
  • 📦 Tree-Shaking - 支持按需打包,减小最终代码体积
  • 📝 完整文档 - 使用 TypeDoc 生成的详细 API 文档
  • 🧪 单元测试 - 使用 Jest 进行完整的单元测试

安装

npm install utils-demo

使用示例

精确数学计算

import { add, multiply, divide } from 'utils-demo';

// 精确的浮点数加法
console.log(add(0.1, 0.2));  // 0.3 而不是 0.30000000000000004

// 精确的浮点数乘法
console.log(multiply(0.1, 0.2));  // 0.02 而不是 0.020000000000000004

// 精确的浮点数除法
console.log(divide(0.3, 0.1));  // 3 而不是 2.9999999999999996

函数工具

import { debounce, throttle } from 'utils-demo';

// 防抖:等待用户停止输入 500ms 后执行搜索
const debouncedSearch = debounce((query: string) => {
    console.log('Searching:', query);
}, 500);

// 节流:限制滚动事件处理频率
const throttledScroll = throttle(() => {
    console.log('Handling scroll...');
}, 1000);

类型检查

import { isNumber, isString } from 'utils-demo';

console.log(isNumber(123));    // true
console.log(isString('abc'));  // true

开发

# 安装依赖
npm install

# 运行测试
npm test

# 构建项目
npm run build

# 生成文档
npm run docs

文档

详细的 API 文档可以通过以下步骤查看:

  1. 克隆项目
  2. 运行 npm install
  3. 运行 npm run docs
  4. 打开 docs/index.html

许可证

MIT

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago