Skip to content

Commit 8cff42e

Browse files
committed
chore: 更新 rspress 配置,添加文档指南和功能描述,导出数学函数
1 parent 52dfd31 commit 8cff42e

5 files changed

Lines changed: 154 additions & 15 deletions

File tree

doc_build/static/search_index.b080fc15.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/guide/getting-started.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: 快速开始
3+
---
4+
5+
# 快速开始
6+
7+
## 安装
8+
9+
使用 npm 或 yarn 安装:
10+
11+
```bash
12+
# 使用 npm
13+
npm install @winner-fed/cloud-utils
14+
15+
# 使用 yarn
16+
yarn add @winner-fed/cloud-utils
17+
18+
# 使用 pnpm
19+
pnpm add @winner-fed/cloud-utils
20+
```
21+
22+
## 基本使用
23+
24+
### 按需引入
25+
26+
```typescript
27+
import { formatDate, debounce } from '@winner-fed/cloud-utils';
28+
29+
// 使用日期格式化
30+
const formattedDate = formatDate(new Date(), 'YYYY-MM-DD');
31+
32+
// 使用防抖函数
33+
const debouncedFn = debounce(() => {
34+
console.log('执行防抖函数');
35+
}, 300);
36+
```
37+
38+
### 完整引入
39+
40+
```typescript
41+
import * as utils from '@winner-fed/cloud-utils';
42+
43+
// 使用工具函数
44+
const result = utils.formatDate(new Date(), 'YYYY-MM-DD');
45+
```
46+
47+
## 示例
48+
49+
### 日期处理
50+
51+
```typescript
52+
import { formatDate, getDateRange } from '@winner-fed/cloud-utils';
53+
54+
// 格式化日期
55+
const date = new Date();
56+
console.log(formatDate(date, 'YYYY-MM-DD HH:mm:ss')); // 2024-03-21 14:30:00
57+
58+
// 获取日期范围
59+
const { start, end } = getDateRange('week');
60+
console.log(start, end); // 本周的开始和结束日期
61+
```
62+
63+
### 函数工具
64+
65+
```typescript
66+
import { debounce, throttle } from '@winner-fed/cloud-utils';
67+
68+
// 防抖函数
69+
const search = debounce((keyword: string) => {
70+
console.log('搜索:', keyword);
71+
}, 300);
72+
73+
// 节流函数
74+
const scrollHandler = throttle(() => {
75+
console.log('滚动事件');
76+
}, 200);
77+
```
78+
79+
### 类型工具
80+
81+
```typescript
82+
import { isNumber, isObject } from '@winner-fed/cloud-utils';
83+
84+
// 类型判断
85+
console.log(isNumber(123)); // true
86+
console.log(isObject({})); // true
87+
```
88+
89+
## 注意事项
90+
91+
1. 建议使用 TypeScript 以获得更好的类型支持
92+
2. 按需引入可以减小打包体积
93+
3. 所有函数都有完整的类型定义
94+
4. 详细的 API 文档请参考 [API 文档](/api/)

docs/index.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,35 @@ pageType: home
33

44
hero:
55
name: cloud-utils
6-
text: 工具类库
6+
text: 一个实用的工具类库
7+
tagline: 简化开发流程,提升开发效率
8+
actions:
9+
- theme: brand
10+
text: 快速开始
11+
link: /guide/getting-started
12+
- theme: alt
13+
text: 查看 API
14+
link: /api/
15+
16+
features:
17+
- icon: ⚡️
18+
title: 开箱即用
19+
details: 提供丰富的工具函数,无需重复造轮子
20+
- icon: 🛠️
21+
title: 类型安全
22+
details: 使用 TypeScript 开发,提供完整的类型定义
23+
- icon: 📦
24+
title: 模块化
25+
details: 按需引入,减小打包体积
26+
- icon: 🔧
27+
title: 可扩展
28+
details: 支持自定义配置,满足不同场景需求
29+
- icon: 📝
30+
title: 文档完善
31+
details: 提供详细的 API 文档和使用示例
32+
- icon: 🔄
33+
title: 持续更新
34+
details: 定期更新,保持代码质量
35+
36+
footer: MIT Licensed | Copyright © 2024-present
737
---

rspress.config.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* @Author: liwb lwbhtml@163.com
3+
* @Date: 2025-04-02 09:23:33
4+
* @LastEditors: liwb lwbhtml@163.com
5+
* @LastEditTime: 2025-04-18 15:19:04
6+
* @FilePath: /cloud-utils/rspress.config.ts
7+
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8+
*/
19
import { defineConfig } from 'rspress/config';
210
import { pluginTypeDoc } from '@rspress/plugin-typedoc';
311
import path from 'path';
@@ -65,14 +73,29 @@ const siteUrl = 'https://winjs-dev.github.io/cloud-utils/';
6573

6674
export default defineConfig({
6775
title: '@winner-fed/cloud-utils',
68-
description: '@winner-fed/cloud-utils API文档',
76+
description: '一个实用的工具类库',
6977
base: '/cloud-utils/',
7078
themeConfig: {
7179
searchPlaceholderText: '搜索文档',
7280
nav: [
81+
{
82+
text: '指南',
83+
link: '/guide/getting-started',
84+
},
7385
{ text: 'API', link: '/api' },
7486
],
7587
sidebar: {
88+
'/guide/': [
89+
{
90+
text: '指南',
91+
items: [
92+
{
93+
text: '快速开始',
94+
link: '/guide/getting-started',
95+
},
96+
],
97+
},
98+
],
7699
'/api/': [
77100
{
78101
text: '核心方法',

src/math.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: liwb lwbhtml@163.com
33
* @Date: 2025-04-18 13:54:44
44
* @LastEditors: liwb lwbhtml@163.com
5-
* @LastEditTime: 2025-04-18 14:01:21
5+
* @LastEditTime: 2025-04-18 15:23:27
66
* @FilePath: /cloud-utils/src/math.ts
77
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
*/
@@ -27,7 +27,7 @@ import { Decimal } from 'decimal.js';
2727
* @returns {number} 商
2828
* @throws {Error} 当除数为0时抛出错误
2929
*/
30-
function mathDivide(arg1: number | string, arg2: number | string, precision: number = 10): number {
30+
export function mathDivide(arg1: number | string, arg2: number | string, precision: number = 10): number {
3131
if (arg2 === 0 || arg2 === '0') {
3232
throw new Error('除数不能为0');
3333
}
@@ -48,7 +48,7 @@ function mathDivide(arg1: number | string, arg2: number | string, precision: num
4848
* @param {number} [precision] 精度,默认保留10位小数
4949
* @returns {number} 和
5050
*/
51-
function mathAdd(arg1: number | string, arg2: number | string, precision: number = 10): number {
51+
export function mathAdd(arg1: number | string, arg2: number | string, precision: number = 10): number {
5252
const x = new Decimal(arg1);
5353
const y = new Decimal(arg2);
5454
return Number(x.plus(y).toDecimalPlaces(precision));
@@ -61,7 +61,7 @@ function mathAdd(arg1: number | string, arg2: number | string, precision: number
6161
* @param {number} [precision] 精度,默认保留10位小数
6262
* @returns {number} 差
6363
*/
64-
function mathSubtract(arg1: number | string, arg2: number | string, precision: number = 10): number {
64+
export function mathSubtract(arg1: number | string, arg2: number | string, precision: number = 10): number {
6565
const x = new Decimal(arg1);
6666
const y = new Decimal(arg2);
6767
return Number(x.minus(y).toDecimalPlaces(precision));
@@ -74,19 +74,12 @@ function mathSubtract(arg1: number | string, arg2: number | string, precision: n
7474
* @param {number} [precision] 精度,默认保留10位小数
7575
* @returns {number} 积
7676
*/
77-
function mathMultiply(arg1: number | string, arg2: number | string, precision: number = 10): number {
77+
export function mathMultiply(arg1: number | string, arg2: number | string, precision: number = 10): number {
7878
const x = new Decimal(arg1);
7979
const y = new Decimal(arg2);
8080
return Number(x.times(y).toDecimalPlaces(precision));
8181
}
8282

83-
export {
84-
mathDivide,
85-
mathAdd,
86-
mathSubtract,
87-
mathMultiply
88-
};
89-
9083
// 测试用例
9184
// console.log(mathDivide(5.1, 3)); // 1.7
9285
// console.log(mathDivide('5.1', '3')); // 1.7

0 commit comments

Comments
 (0)