@pmun/utils 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/index.d.ts +1201 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 sunpm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# sunpm-utils
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/sunpm-utils)
|
|
4
|
+
[](https://github.com/sunpm/sunpm-utils/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
一个轻量级、模块化的 TypeScript 工具函数库,为日常开发提供便捷实用的工具集合。
|
|
7
|
+
|
|
8
|
+
## 特点
|
|
9
|
+
|
|
10
|
+
- 🚀 **轻量级**:按需引入,不增加项目体积
|
|
11
|
+
- 🧩 **模块化**:合理划分模块,易于使用和维护
|
|
12
|
+
- 📦 **零依赖**:除日期处理外无外部依赖
|
|
13
|
+
- 🔒 **类型安全**:完全使用 TypeScript 编写,提供完整类型定义
|
|
14
|
+
- 💯 **测试全面**:每个函数都有完善的单元测试
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# npm
|
|
20
|
+
npm install sunpm-utils
|
|
21
|
+
|
|
22
|
+
# yarn
|
|
23
|
+
yarn add sunpm-utils
|
|
24
|
+
|
|
25
|
+
# pnpm
|
|
26
|
+
pnpm add sunpm-utils
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 使用
|
|
30
|
+
|
|
31
|
+
从主入口导入需要的函数:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// 导入需要的函数
|
|
35
|
+
import { chunk, formatDate, isString, unique } from 'sunpm-utils'
|
|
36
|
+
|
|
37
|
+
// 使用数组工具函数
|
|
38
|
+
const arr = [1, 2, 2, 3, 3, 4]
|
|
39
|
+
const uniqueArr = unique(arr) // [1, 2, 3, 4]
|
|
40
|
+
const chunks = chunk(arr, 2) // [[1, 2], [2, 3], [3, 4]]
|
|
41
|
+
|
|
42
|
+
// 使用日期格式化
|
|
43
|
+
const formattedDate = formatDate(new Date(), 'YYYY-MM-DD') // 例如:'2023-11-10'
|
|
44
|
+
|
|
45
|
+
// 使用类型检查
|
|
46
|
+
console.log(isString('hello')) // true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 功能模块
|
|
50
|
+
|
|
51
|
+
库中包含以下功能模块的工具函数:
|
|
52
|
+
|
|
53
|
+
- **数组操作 (array)**:数组去重、分块、查找、过滤、转换等处理函数
|
|
54
|
+
- **日期时间 (date)**:日期格式化、计算、比较等函数
|
|
55
|
+
- **字符串处理 (string)**:字符串转换、格式化、验证等
|
|
56
|
+
- **对象操作 (object)**:对象深拷贝、合并、转换等
|
|
57
|
+
- **数字处理 (number)**:数字格式化、四舍五入、范围控制等
|
|
58
|
+
- **类型检查 (is)**:各种数据类型的判断函数
|
|
59
|
+
|
|
60
|
+
## 文档
|
|
61
|
+
|
|
62
|
+
本项目使用 TypeDoc 自动生成文档,可通过以下方式查看:
|
|
63
|
+
|
|
64
|
+
1. **在线文档**:访问 [https://sunpm.github.io/sunpm-utils/](https://sunpm.github.io/sunpm-utils/)(需要部署后访问)
|
|
65
|
+
|
|
66
|
+
2. **本地查看**:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# 生成文档
|
|
70
|
+
pnpm docs
|
|
71
|
+
|
|
72
|
+
# 在浏览器中打开
|
|
73
|
+
open docs/index.html
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
3. **部署文档**:
|
|
77
|
+
```bash
|
|
78
|
+
# 生成并部署到 GitHub Pages
|
|
79
|
+
pnpm docs:deploy
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
详细的 API 文档中包含每个函数的说明、参数、返回值和使用示例。
|
|
83
|
+
|
|
84
|
+
## 许可证
|
|
85
|
+
|
|
86
|
+
[MIT](LICENSE)
|