@movk/core 0.0.4 → 1.0.0
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/README.md +98 -147
- package/dist/index.d.mts +1370 -666
- package/dist/index.d.ts +1370 -666
- package/dist/index.mjs +1 -1
- package/package.json +34 -38
package/README.md
CHANGED
|
@@ -1,205 +1,156 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://core.mhaibaraai.cn/)
|
|
2
|
+
|
|
3
|
+
> `@movk/core` 是一个为 TypeScript 项目设计的现代化、支持 tree-shaking 的工具函数库,涵盖了数组、对象、字符串、异步操作等多个方面。
|
|
2
4
|
|
|
3
5
|
[](https://www.typescriptlang.org/)
|
|
4
|
-
[](https://github.com/antfu/eslint-config)
|
|
5
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
6
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
7
8
|
[![bundle][bundle-src]][bundle-href]
|
|
8
9
|
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
9
10
|
[![License][license-src]][license-href]
|
|
11
|
+
[![Movk Nuxt Docs][movk-nuxt-docs-src]][movk-nuxt-docs-href]
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
- 📖 [在线文档](https://core.mhaibaraai.cn)
|
|
12
14
|
|
|
13
15
|
## ✨ 特性
|
|
14
16
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
- ⚡ **现代化** - 基于最新的 ES 模块和构建工具
|
|
21
|
-
- 📦 **轻量级** - 按需导入,最小化打包体积
|
|
17
|
+
- **现代化**: 使用 TypeScript 构建,提供完整的类型定义。
|
|
18
|
+
- **Tree-Shaking**: 只打包你需要的代码,减小生产环境的包体积。
|
|
19
|
+
- **功能丰富**: 涵盖数组、对象、字符串、异步等多种工具函数。
|
|
20
|
+
- **组合式**: 提供 Vue Composables,方便在 Vue 项目中使用。
|
|
21
|
+
- **文档齐全**: 提供完善的文档和示例。
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## 🚀 快速开始
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
# npm
|
|
27
|
-
npm install @movk/core
|
|
28
|
-
|
|
29
|
-
# yarn
|
|
30
|
-
yarn add @movk/core
|
|
31
|
-
|
|
32
26
|
# pnpm
|
|
33
27
|
pnpm add @movk/core
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## 🚀 快速开始
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { debounce, deepClone, TreeNode, useAppStorage } from '@movk/core'
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
key: 'app-config',
|
|
44
|
-
defaultValue: { theme: 'light' }
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// 使用防抖函数
|
|
48
|
-
const debouncedSearch = debounce((query: string) => {
|
|
49
|
-
// 搜索逻辑
|
|
50
|
-
}, 300)
|
|
51
|
-
|
|
52
|
-
// 深度克隆对象
|
|
53
|
-
const cloned = deepClone(originalObject)
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## 📚 功能模块
|
|
57
|
-
|
|
58
|
-
### 🎯 Composables
|
|
59
|
-
|
|
60
|
-
Vue 3 组合式函数,提供响应式的状态管理和通用功能。
|
|
61
|
-
|
|
62
|
-
- **`useAppStorage`** - 应用存储管理,支持 localStorage 和 sessionStorage
|
|
63
|
-
- **`useCopyCode`** - 代码复制功能,支持多种格式和自定义处理
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import { useAppStorage } from '@movk/core'
|
|
29
|
+
# yarn
|
|
30
|
+
yarn add @movk/core
|
|
67
31
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
defaultValue: { theme: 'light', language: 'zh-CN' }
|
|
71
|
-
})
|
|
32
|
+
# npm
|
|
33
|
+
npm install @movk/core
|
|
72
34
|
```
|
|
73
35
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
全面的工具函数库,覆盖常见的开发需求。
|
|
77
|
-
|
|
78
|
-
#### 🔄 异步工具 (Async)
|
|
79
|
-
|
|
80
|
-
- **`debounce`** - 防抖函数
|
|
81
|
-
- **`throttle`** - 节流函数
|
|
82
|
-
- **`sleep`** - 睡眠延迟函数
|
|
83
|
-
|
|
84
|
-
#### 📊 数组操作 (Array)
|
|
85
|
-
|
|
86
|
-
- **`operations`** - 数组操作工具集
|
|
36
|
+
## 📖 API 参考
|
|
87
37
|
|
|
88
|
-
|
|
38
|
+
### Composables (组合式函数)
|
|
89
39
|
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
- **`omit`** - 排除对象属性
|
|
93
|
-
- **`separate`** - 对象分离
|
|
94
|
-
- **`convert`** - 对象转换
|
|
40
|
+
- `useAppStorage`: 用于管理 `localStorage` 或 `sessionStorage` 中应用程序数据的组合式函数。
|
|
41
|
+
- `useCopyCode`: 用于将文本复制到剪贴板的组合式函数。
|
|
95
42
|
|
|
96
|
-
|
|
43
|
+
### Utils (工具函数)
|
|
97
44
|
|
|
98
|
-
|
|
45
|
+
#### Array (数组)
|
|
99
46
|
|
|
100
|
-
|
|
47
|
+
- `unique`: 创建一个不含重复元素的数组副本。
|
|
48
|
+
- `chunk`: 将数组拆分成多个指定大小的块。
|
|
49
|
+
- `flatten`: 将嵌套数组展平到指定深度。
|
|
101
50
|
|
|
102
|
-
|
|
103
|
-
- **`formatFileSize`** - 文件大小格式化
|
|
104
|
-
- **`convertSvgToPng`** - SVG 转 PNG
|
|
105
|
-
- **`replaceCurrentColor`** - 替换当前颜色
|
|
51
|
+
#### Async (异步)
|
|
106
52
|
|
|
107
|
-
|
|
53
|
+
- `throttle`: 创建一个节流函数,在指定时间间隔内最多只执行一次。
|
|
54
|
+
- `debounce`: 创建一个防抖函数,在指定延迟后执行,延迟时间会在每次调用时重置。
|
|
55
|
+
- `sleep`: 将执行暂停指定的毫秒数。
|
|
56
|
+
- `sleepWithCancel`: 可取消的 `sleep` 版本。
|
|
108
57
|
|
|
109
|
-
|
|
58
|
+
#### File (文件)
|
|
110
59
|
|
|
111
|
-
|
|
60
|
+
- `formatFileSize`: 将文件大小(字节)格式化为人类可读的字符串。
|
|
61
|
+
- `extractFilename`: 从 `Content-Disposition` 响应头中提取文件名。
|
|
62
|
+
- `triggerDownload`: 在浏览器中触发文件下载。
|
|
112
63
|
|
|
113
|
-
|
|
64
|
+
#### Object (对象)
|
|
114
65
|
|
|
115
|
-
-
|
|
66
|
+
- `isValidContainer`: 检查一个值是否为有效的容器(对象或数组)。
|
|
67
|
+
- `toPath`: 将路径字符串或数组转换为路径数组。
|
|
68
|
+
- `getPath`: 获取对象中指定路径的值。
|
|
69
|
+
- `setPath`: 设置对象中指定路径的值。
|
|
70
|
+
- `joinPath`: 将多个路径片段连接成一个路径字符串。
|
|
71
|
+
- `deepClone`: 创建一个值的深拷贝。
|
|
72
|
+
- `pick`: 从对象中挑选指定的属性,创建一个新对象。
|
|
73
|
+
- `separate`: 将对象根据指定的键分割成两个对象。
|
|
74
|
+
- `separateMany`: 根据多个键组将对象分割成多个对象。
|
|
75
|
+
- `convertToKebabCase`: 将对象的所有键转换为 kebab-case 格式。
|
|
76
|
+
- `omit`: `pick` 的反向操作;创建一个省略了指定属性的新对象。
|
|
77
|
+
- `omitUndefined`: 创建一个移除了所有 `undefined` 属性的新对象。
|
|
116
78
|
|
|
117
|
-
|
|
118
|
-
import { TreeNode } from '@movk/core'
|
|
79
|
+
#### String (字符串)
|
|
119
80
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
81
|
+
- `startCase`: 将字符串转换为 [Start Case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage) 格式。
|
|
82
|
+
- `camelCase`: 将字符串转换为 [camelCase](https://en.wikipedia.org/wiki/Camel_case) 格式。
|
|
83
|
+
- `kebabCase`: 将字符串转换为 [kebab-case](https://en.wikipedia.org/wiki/Kebab_case) 格式。
|
|
84
|
+
- `snakeCase`: 将字符串转换为 [snake_case](https://en.wikipedia.org/wiki/Snake_case) 格式。
|
|
85
|
+
- `pascalCase`: 将字符串转换为 [PascalCase](https://en.wikipedia.org/wiki/Pascal_case) 格式。
|
|
86
|
+
- `capitalize`: 将字符串的第一个字符转换为大写,其余转换为小写。
|
|
87
|
+
- `upperFirst`: 将字符串的第一个字符转换为大写。
|
|
88
|
+
- `lowerFirst`: 将字符串的第一个字符转换为小写。
|
|
89
|
+
- `upperCase`: 将整个字符串转换为大写。
|
|
90
|
+
- `lowerCase`: 将整个字符串转换为小写。
|
|
91
|
+
- `words`: 将字符串拆分为一个单词数组。
|
|
127
92
|
|
|
128
|
-
|
|
129
|
-
- **`preset-owl`** - OWL (Object - Where - Layout) 模式预设
|
|
93
|
+
#### Tree (树)
|
|
130
94
|
|
|
131
|
-
|
|
95
|
+
一个包含用于处理树状数据结构的静态方法的类。
|
|
132
96
|
|
|
133
|
-
|
|
97
|
+
- `fromList`: 将扁平的对象列表转换为树状结构。
|
|
98
|
+
- `toList`: 将树状结构转换为扁平的对象列表。
|
|
99
|
+
- `estimateSize`: 估算树中的节点总数。
|
|
100
|
+
- `find`: 查找树中满足条件的第一个节点。
|
|
101
|
+
- `findAll`: 查找树中所有满足条件的节点。
|
|
102
|
+
- `findById`: 按 ID 查找树中的节点。
|
|
103
|
+
- `getStats`: 获取关于树的统计信息(总节点数、叶子节点数、深度等)。
|
|
104
|
+
- `filter`: 过滤树,只保留满足条件的节点(及其祖先)。
|
|
105
|
+
- `transform`: 创建一个具有相同结构的新树,但每个节点都经过转换函数处理。
|
|
106
|
+
- `forEach`: 对树中的每个节点执行一次提供的函数。
|
|
107
|
+
- `insertBefore`: 在目标节点之前插入一个新节点。
|
|
108
|
+
- `insertAfter`: 在目标节点之后插入一个新节点。
|
|
109
|
+
- `remove`: 从树中移除一个节点。
|
|
110
|
+
- `validate`: 验证树结构的完整性。
|
|
134
111
|
|
|
135
|
-
|
|
136
|
-
- pnpm 9+
|
|
137
|
-
|
|
138
|
-
### 开发命令
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
# 安装依赖
|
|
142
|
-
pnpm install
|
|
112
|
+
#### Utilities (实用工具)
|
|
143
113
|
|
|
144
|
-
|
|
145
|
-
|
|
114
|
+
- `getRandomUUID`: 生成一个随机的 UUID。
|
|
115
|
+
- `simpleHash`: 从字符串创建一个简单的哈希值。
|
|
146
116
|
|
|
147
|
-
|
|
148
|
-
pnpm build
|
|
117
|
+
#### Validator (验证器)
|
|
149
118
|
|
|
150
|
-
|
|
151
|
-
|
|
119
|
+
- `isObject`: 检查值是否为对象。
|
|
120
|
+
- `isArray`: 检查值是否为数组。
|
|
121
|
+
- `isString`: 检查值是否为字符串。
|
|
122
|
+
- `isNumber`: 检查值是否为数字。
|
|
123
|
+
- `isFunction`: 检查值是否为函数。
|
|
124
|
+
- `isEmpty`: 检查值是否为空。
|
|
125
|
+
- `isPlainObject`: 检查值是否为纯粹的对象(plain object)。
|
|
152
126
|
|
|
153
|
-
|
|
154
|
-
pnpm lint
|
|
127
|
+
## ⚡ 技术栈
|
|
155
128
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
pnpm release
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### 项目结构
|
|
164
|
-
|
|
165
|
-
```tree
|
|
166
|
-
movk-core/
|
|
167
|
-
├── src/
|
|
168
|
-
│ ├── composables/ # Vue 组合式函数
|
|
169
|
-
│ ├── constants/ # 常量定义
|
|
170
|
-
│ ├── data-structures/ # 数据结构实现
|
|
171
|
-
│ ├── framework/ # 框架预设
|
|
172
|
-
│ ├── types/ # TypeScript 类型定义
|
|
173
|
-
│ └── utils/ # 工具函数
|
|
174
|
-
│ ├── array/ # 数组工具
|
|
175
|
-
│ ├── async/ # 异步工具
|
|
176
|
-
│ ├── file/ # 文件操作
|
|
177
|
-
│ ├── object/ # 对象处理
|
|
178
|
-
│ ├── string/ # 字符串处理
|
|
179
|
-
│ ├── utilities/ # 通用工具
|
|
180
|
-
│ └── validator/ # 验证器
|
|
181
|
-
├── tests/ # 测试文件
|
|
182
|
-
└── scripts/ # 构建脚本
|
|
183
|
-
```
|
|
129
|
+
- [TypeScript](https://www.typescriptlang.org/) - JavaScript 的超集
|
|
130
|
+
- [Vitest](https://vitest.dev/) - 测试框架
|
|
131
|
+
- [Unbuild](https://github.com/unjs/unbuild) - 构建工具
|
|
132
|
+
- [pnpm](https://pnpm.io/) - 包管理器
|
|
184
133
|
|
|
185
134
|
## 📄 许可证
|
|
186
135
|
|
|
187
|
-
[MIT](./LICENSE) License ©
|
|
188
|
-
|
|
189
|
-
## 📞 支持
|
|
190
|
-
|
|
191
|
-
- [GitHub Issues](https://github.com/mhaibaraai/movk-core/issues)
|
|
192
|
-
- [文档](https://github.com/mhaibaraai/movk-core)
|
|
136
|
+
[MIT](./LICENSE) License © 2024-PRESENT [YiXuan](https://github.com/mhaibaraai)
|
|
193
137
|
|
|
194
138
|
<!-- Badges -->
|
|
195
139
|
|
|
196
140
|
[npm-version-src]: https://img.shields.io/npm/v/@movk/core?style=flat&colorA=080f12&colorB=1fa669
|
|
197
141
|
[npm-version-href]: https://npmjs.com/package/@movk/core
|
|
142
|
+
|
|
198
143
|
[npm-downloads-src]: https://img.shields.io/npm/dm/@movk/core?style=flat&colorA=080f12&colorB=1fa669
|
|
199
144
|
[npm-downloads-href]: https://npmjs.com/package/@movk/core
|
|
145
|
+
|
|
200
146
|
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@movk/core?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
201
147
|
[bundle-href]: https://bundlephobia.com/result?p=@movk/core
|
|
148
|
+
|
|
202
149
|
[license-src]: https://img.shields.io/github/license/mhaibaraai/movk-core.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
203
150
|
[license-href]: https://github.com/mhaibaraai/movk-core/blob/main/LICENSE.md
|
|
151
|
+
|
|
204
152
|
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
205
153
|
[jsdocs-href]: https://www.jsdocs.io/package/@movk/core
|
|
154
|
+
|
|
155
|
+
[movk-nuxt-docs-src]: https://img.shields.io/npm/v/@movk/nuxt-docs?label=Movk%20Nuxt%20Docs&color=00DC82
|
|
156
|
+
[movk-nuxt-docs-href]: https://docs.mhaibaraai.cn
|