@vueboot/helper 0.0.0-stage → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ygzhang-lab
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 CHANGED
@@ -1,3 +1,236 @@
1
- # Temporary Holding Version
1
+ # @vueboot/helper — 通用工具函数
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ← [VueBoot](../../README.md) · [接口参考(API)](./API.md)
4
+
5
+ **Tree-shaking**:支持(ESM only + `sideEffects: false`,模块求值无副作用,按名导入即可移除未使用的导出)。
6
+
7
+ 零依赖工具包,覆盖日常业务里反复重写的工具函数:
8
+
9
+ - **验证**:空值、数字、普通对象、邮箱、URL、手机号、身份证、统一社会信用代码
10
+ - **字符串**:ASCII 命名转换、截断、清理、去 HTML、敏感信息脱敏
11
+ - **数字**:区间限制、四舍五入 / 向下 / 向上取整、固定小数位
12
+ - **格式化**:金额千分位、大写人民币、字节数、K / W 展示
13
+ - **随机**:随机字符串、指定长度随机整数、区间随机整数 / 浮点数
14
+ - **对象**:深拷贝、深合并
15
+ - **函数**:防抖、节流
16
+ - **其它**:任意值转布尔、文件扩展名转 MIME
17
+
18
+ ESM only、`sideEffects: false`,按函数具名导入即可 tree-shake;不依赖 Vue,也不访问 `window` / `document` 等 DOM API,可在 Node / SSR / 浏览器使用(依赖运行时内置的 `URL` 与定时器)。
19
+
20
+ ## 安装
21
+
22
+ ```bash
23
+ pnpm add @vueboot/helper
24
+ ```
25
+
26
+ 没有 peer 依赖,Node 18+ / 任意现代打包器。
27
+
28
+ ## 快速开始
29
+
30
+ ```ts
31
+ import {
32
+ isEmpty,
33
+ isChinaMobile,
34
+ camelCase,
35
+ cutString,
36
+ rangeClamp,
37
+ debounce,
38
+ } from "@vueboot/helper";
39
+
40
+ isEmpty(" "); // false —— 空白字符串不算空
41
+ isChinaMobile("13812345678"); // true
42
+ camelCase("user_profile-name"); // "userProfileName"
43
+ cutString("VueBoot 是一个多包仓库", 8); // "VueBo..."
44
+ rangeClamp(120, 0, 100); // 100
45
+ const search = debounce((keyword: string) => fetch(`/api?q=${keyword}`), 300);
46
+ ```
47
+
48
+ ## 导出总览
49
+
50
+ | 分类 | 函数 |
51
+ | --- | --- |
52
+ | 断言 | `assertString` / `assertNumber` / `assertRangeNumber` / `assertPrecision` / `assertArray` |
53
+ | 验证 | `isEmpty` / `isNumeric` / `isPlainObject` / `isEmail` / `isHttpUrl` / `isChinaMobile` / `isChinaIdCard` / `isChinaUSCC` |
54
+ | 字符串 | `capitalize` / `camelCase` / `pascalCase` / `kebabCase` / `snakeCase` / `cutString` / `cleanString` / `stripHtml` / `maskSensitive` |
55
+ | 数字 | `rangeClamp` / `toRound` / `toFloor` / `toCeil` / `inRange` / `toFixed` |
56
+ | 格式化 | `formatMoney` / `formatMoneyUpper` / `formatBytes` / `formatKW` |
57
+ | 随机 | `randomString` / `randomInteger` / `randomInt` / `randomFloat` |
58
+ | 对象 | `deepClone` / `deepMerge` |
59
+ | 函数 | `debounce` / `throttle` |
60
+ | 转换 | `toBool` |
61
+ | 文件 | `fileExtToMime` |
62
+
63
+ 完整签名、边界与错误形状见 [API.md](./API.md)。
64
+
65
+ ## 常用任务
66
+
67
+ ### 表单校验
68
+
69
+ ```ts
70
+ import {
71
+ isEmpty,
72
+ isEmail,
73
+ isChinaMobile,
74
+ isChinaIdCard,
75
+ isChinaUSCC,
76
+ } from "@vueboot/helper";
77
+
78
+ // 空值只回答「容器里有没有东西」,空白字符串不算空
79
+ isEmpty(""); // true
80
+ isEmpty(" "); // false
81
+
82
+ isEmail("dev@example.com"); // true
83
+ isChinaMobile("13812345678"); // true
84
+ isChinaIdCard("11010519491231002X"); // true —— 校验码与出生日期都正确
85
+ isChinaUSCC("91350100M000100Y43"); // true
86
+ ```
87
+
88
+ 这些校验都只做格式与校验码判断,不代表号码真实归属或企业真实存在。`isEmail` 是轻量规则,**不支持 `user+tag@example.com` 这类 `+` 标签**。
89
+
90
+ ### 字段命名转换
91
+
92
+ ```ts
93
+ import { camelCase, pascalCase, kebabCase, snakeCase, capitalize } from "@vueboot/helper";
94
+
95
+ camelCase("user_profile-name"); // "userProfileName"
96
+ pascalCase("user_profile-name"); // "UserProfileName"
97
+ kebabCase("XMLParser"); // "xml-parser"
98
+ snakeCase("XMLParser"); // "xml_parser"
99
+ capitalize("user"); // "User"
100
+ ```
101
+
102
+ 分词只认 ASCII 字母数字,中文等非 ASCII 字符会被当作分隔符丢弃。
103
+
104
+ ### 展示文本清理与脱敏
105
+
106
+ ```ts
107
+ import { cutString, cleanString, stripHtml, maskSensitive } from "@vueboot/helper";
108
+
109
+ cutString("hello world", 8); // "hello..."
110
+ cleanString(" a\nb "); // "ab"
111
+ stripHtml("<p>Hello <b>world</b></p>"); // "Hello world"
112
+
113
+ maskSensitive("13812345678"); // "138****5678"
114
+ maskSensitive("user@example.com"); // "use***@example.com"
115
+ maskSensitive("张三"); // "张*"
116
+ ```
117
+
118
+ `cutString` 的返回值长度不超过 `maxLength`;`stripHtml` 是纯正则实现,不解码 HTML 实体;`maskSensitive` 会按手机号 / 邮箱 / 身份证 / 固话 / 车牌 / 姓名依次识别。
119
+
120
+ ### 数字处理
121
+
122
+ ```ts
123
+ import { rangeClamp, inRange, toRound, toFloor, toCeil, toFixed } from "@vueboot/helper";
124
+
125
+ rangeClamp(120, 0, 100); // 100
126
+ inRange(3, 1, 3); // true —— 闭区间
127
+ toRound(1.2345, 2); // 1.23
128
+ toFloor("1.239", 2); // 1.23
129
+ toCeil(1.231, 2); // 1.24
130
+ toFixed(1.2, 2); // "1.20"
131
+ ```
132
+
133
+ `rangeClamp` / `inRange` 的 `min > max` 会抛 `RangeError`;`toRound` / `toFloor` / `toCeil` 接受数字或数字字符串,非法值统一返回 `0`;精度必须是 `0..100` 的整数。
134
+
135
+ ### 金额与字节展示
136
+
137
+ ```ts
138
+ import {
139
+ formatMoney,
140
+ formatMoneyUpper,
141
+ formatBytes,
142
+ formatKW,
143
+ } from "@vueboot/helper";
144
+
145
+ formatMoney(1234567.89); // "¥1,234,567.89元"
146
+ formatMoney(-1234.5, "", ""); // "-1,234.50"
147
+ formatMoneyUpper(1234.56); // "壹仟贰佰叁拾肆元伍角陆分"
148
+ formatBytes(10241234); // "9.77 MB"
149
+ formatKW(1032550); // "103.2W"
150
+ ```
151
+
152
+ `formatMoney` 固定保留两位小数;`formatMoneyUpper` 支持到「仟亿」级,更大的金额返回空串;`formatBytes` 使用向上舍入、`formatKW` 使用向下舍入,两者的精度都必须是 `0..100` 的整数。
153
+
154
+ ### 随机数与随机字符串
155
+
156
+ ```ts
157
+ import {
158
+ randomString,
159
+ randomInteger,
160
+ randomInt,
161
+ randomFloat,
162
+ } from "@vueboot/helper";
163
+
164
+ randomString(); // 16 位,例如 "aB3dE9fG2hJ5kL7m"
165
+ randomString(8, "0123456789"); // 8 位数字
166
+ randomInteger(4); // 4 位整数,例如 5231(首位不为 0)
167
+ randomInt(1, 10); // 1~10 的整数
168
+ randomFloat(0, 1); // 0~1 的浮点数,例如 0.42
169
+ ```
170
+
171
+ 优先使用 `globalThis.crypto.getRandomValues`(拒绝采样,无取模偏差);运行环境不支持时退回 `Math.random`,此时**不是密码学安全**的。`randomString` 首字符不会取数字(字符集全部是数字时除外);`randomInteger` 的位数上限为 15(保证安全整数);`randomInt` / `randomFloat` 都是闭区间,`min > max` 抛 `RangeError`。`randomFloat` 的精度必须是 `0..100` 的整数。
172
+
173
+ ### 深拷贝与深合并
174
+
175
+ ```ts
176
+ import { deepClone, deepMerge } from "@vueboot/helper";
177
+
178
+ const source = { nested: { count: 1 }, list: [1, 2] };
179
+ const copy = deepClone(source); // 无共享引用,支持循环引用、Date、RegExp、Map、Set
180
+
181
+ const merged = deepMerge({ nested: { a: 1 } }, { nested: { b: 2 } });
182
+ merged; // { nested: { a: 1, b: 2 } }
183
+ ```
184
+
185
+ `deepMerge` 只在两侧都是普通对象时递归合并,数组整体覆盖;不修改入参,并跳过 `__proto__` 键防止原型污染。
186
+
187
+ ### 交互与配置
188
+
189
+ ```ts
190
+ import { debounce, throttle, toBool, fileExtToMime } from "@vueboot/helper";
191
+
192
+ const onInput = debounce((value: string) => save(value), 300);
193
+ const onScroll = throttle(() => updateLayout(), 100);
194
+
195
+ toBool("yes"); // true
196
+ toBool("0"); // false
197
+ toBool(" "); // true —— 未命中配置列表的非空字符串
198
+
199
+ fileExtToMime(".PNG"); // "image/png"
200
+ ```
201
+
202
+ `debounce` / `throttle` 返回带内部状态的闭包,但模块求值本身没有副作用;`toBool` 可用第二、第三个参数自定义 true / false 字符串列表。
203
+
204
+ ## FAQ
205
+
206
+ **`isEmpty` 为什么把空白字符串 / `0` / `false` 当非空?**
207
+ 它只回答「容器里有没有东西」,不做业务意义上的「有没有值」。空白字符串长度不为 0,`0` 和 `false` 是合法业务值。需要「空白也算空」时先 `value.trim()` 再判断。
208
+
209
+ **`toRound` 为什么把 `NaN` / `"abc"` 返回 `0`?**
210
+ 本包把「无法参与计算的输入」统一视为 `0`,避免 `NaN` 在页面渲染和后续运算里扩散。需要区分「输入非法」与「结果为零」时,先用 `isNumeric` 判断,再调用取整函数。
211
+
212
+ **`toRound(1.005, 2)` 为什么得到 `1`?**
213
+ `1.005` 在 IEEE-754 双精度下的实际值略小于 `1.005`,乘 `100` 后小于 `100.5`,`Math.round` 自然不进位。金额等精度敏感场景建议用整数分单位。
214
+
215
+ **`deepMerge` 的数组为什么不是逐项合并?**
216
+ 逐项合并会让「替换列表」变得无法表达。这里选择让数组作为完整的值被后者覆盖,普通对象才递归合并。需要追加列表请在业务层显式处理。
217
+
218
+ **为什么 `debounce` / `throttle` / 随机函数不算「纯函数」?**
219
+ `debounce` / `throttle` 返回的函数内部持有计时器状态;随机函数(`randomString` / `randomInteger` / `randomInt` / `randomFloat`)的同一输入会得到不同输出。但模块本身没有模块级可变状态,`import` 不会产生副作用,tree-shaking 不受影响。其余函数仍是同一输入同一输出的纯函数。
220
+
221
+ **随机函数可以生成密码或安全令牌吗?**
222
+ 优先走 `crypto.getRandomValues` 时是安全随机源,可用于一般标识、验证码串等;但在不提供 Web Crypto 的环境会退回 `Math.random`,不具备密码学安全性。对安全强度有硬要求时请使用专门的密码学库,并在调用方确认随机源。
223
+
224
+ **tree-shaking 如何生效?**
225
+ `package.json` 声明 `"sideEffects": false`,源码全部具名导出且模块求值无副作用。按名字导入(如 `import { isEmpty } from "@vueboot/helper"`)即可只保留用到的函数;`import * as helper` 会削弱这一点。
226
+
227
+ ## 与业务层的边界
228
+
229
+ 本包只做通用的判断、转换与组合,不提供本地化文案、表单框架集成、请求封装、日志或状态管理,也不导出 Vue 组件 / composable。
230
+
231
+ 断言函数抛 `TypeError` / `RangeError`,取整与区间函数在参数写错时抛 `RangeError`;这些都是编程错误,不应当作面向用户的提示文案。
232
+
233
+ ## 延伸阅读
234
+
235
+ - [接口参考(API.md)](./API.md):全部签名、参数、返回值、边界、错误与版本约定。
236
+ - [VueBoot](../../README.md):VueBoot 整体定位与五个子包的分工。
@@ -0,0 +1,391 @@
1
+ /**
2
+ * 断言工具:参数类型与范围的防御性检查,失败时抛错。
3
+ *
4
+ * 消息统一以 `[helper]` 开头;`funcName` / `valName` 用于补充调用位置。
5
+ */
6
+ /**
7
+ * 断言值必须是字符串,否则抛 `TypeError`。
8
+ */
9
+ declare function assertString(val: unknown, funcName?: string, valName?: string): void;
10
+ /**
11
+ * 断言值必须是 `number` 类型(不排除 `NaN` / `±Infinity`),否则抛 `TypeError`。
12
+ */
13
+ declare function assertNumber(val: unknown, funcName?: string, valName?: string): void;
14
+ /**
15
+ * 断言区间合法:`min` / `max` 不是 `NaN` 且 `min <= max`,否则抛 `RangeError`。
16
+ */
17
+ declare function assertRangeNumber(min: number, max: number, funcName?: string): void;
18
+ /**
19
+ * 断言精度是 `0` 到 `100` 的整数,否则抛 `RangeError`。
20
+ */
21
+ declare function assertPrecision(precision: number): void;
22
+ /**
23
+ * 断言值必须是数组,否则抛 `TypeError`。
24
+ */
25
+ declare function assertArray(val: unknown, funcName?: string, valName?: string): void;
26
+
27
+ /**
28
+ * 验证工具:只做结构与格式判断,不做任何数据转换。
29
+ */
30
+ /**
31
+ * 判断值是否为空。
32
+ *
33
+ * 只有以下情况算空:`null` / `undefined`、空字符串、空数组、空 `Map` / `Set`、
34
+ * 没有自有可枚举字符串键的普通对象。空白字符串、`0`、`false`、`NaN`、`Date`
35
+ * 以及函数都不算空。
36
+ */
37
+ declare function isEmpty(value: unknown): boolean;
38
+ /**
39
+ * 判断是否为数字或可完整转换为有限数字的字符串。
40
+ *
41
+ * 只接受 `number` 与 `string` 两种类型:`number` 必须是有限值(`NaN`、
42
+ * `±Infinity` 为 `false`);字符串会先 `trim`,空串与 `"NaN"` / `"Infinity"`
43
+ * 等不可解析为有限数字的值均为 `false`。布尔值、数组、`null` 等一律 `false`。
44
+ */
45
+ declare function isNumeric(value: unknown): boolean;
46
+ /**
47
+ * 判断是否为普通对象:原型为 `Object.prototype` 或 `null`。
48
+ *
49
+ * 类实例、数组、函数、`Date`、`Map` / `Set`、包装对象均为 `false`;
50
+ * `Object.create(null)` 为 `true`。
51
+ */
52
+ declare function isPlainObject(value: unknown): boolean;
53
+ /**
54
+ * 判断是否为 `http` / `https` 绝对地址。
55
+ *
56
+ * 依赖 `URL` 解析:相对路径、缺少协议的字符串、`ftp:` 等其它协议都返回 `false`。
57
+ */
58
+ declare function isHttpUrl(value: unknown): boolean;
59
+ /**
60
+ * 判断是否为邮箱地址。
61
+ *
62
+ * 规则为 `local@domain.tld` 的轻量格式校验,不实现 RFC 5322 全集:
63
+ * `local` 由字母、数字、下划线、点和连字符组成(不支持 `+` 标签),
64
+ * 域名必须包含点且不能以下划线拼接,前后含空白字符也判失败。
65
+ */
66
+ declare function isEmail(value: unknown): boolean;
67
+ /**
68
+ * 判断是否为中国大陆手机号:1 开头、第二位 3-9、共 11 位数字。
69
+ */
70
+ declare function isChinaMobile(value: unknown): boolean;
71
+ /**
72
+ * 判断是否为中国大陆二代身份证号(GB 11643-1999)。
73
+ *
74
+ * 同时校验:18 位格式(17 位数字 + 数字或 `X`)、出生日期真实存在且不晚于
75
+ * 当前时间、以及 ISO 7064:1983 MOD 11-2 校验码。不校验行政区划码是否分配。
76
+ */
77
+ declare function isChinaIdCard(value: unknown): boolean;
78
+ /**
79
+ * 判断是否为统一社会信用代码(GB 32100-2015)。
80
+ * https://www.cods.org.cn/cods/2024-07/26/article_2024072615445218813.html
81
+ * 同时校验:18 位字符集(不含 `I` / `O` / `S` / `V` / `Z`)与
82
+ * 加权求和 MOD 31 校验码。不区分登记管理部门与主体类型。
83
+ */
84
+ declare function isChinaUSCC(value: unknown): boolean;
85
+
86
+ /**
87
+ * 字符串工具:ASCII 字母数字的分词、大小写转换、截断与脱敏。
88
+ */
89
+ /**
90
+ * 首字符转大写,其余字符保持不变;空字符串原样返回。
91
+ */
92
+ declare function capitalize(value: string): string;
93
+ /**
94
+ * 转为小驼峰:`"foo-bar_baz"` → `"fooBarBaz"`,`"XMLParser"` → `"xmlParser"`。
95
+ */
96
+ declare function camelCase(value: string): string;
97
+ /**
98
+ * 转为大驼峰命名:`"hello_world"` → `"HelloWorld"`,`"XMLParser"` → `"XmlParser"`。
99
+ */
100
+ declare function pascalCase(value: string): string;
101
+ /**
102
+ * 转为短横线命名:`"FooBar"` → `"foo-bar"`,`"XMLParser"` → `"xml-parser"`。
103
+ */
104
+ declare function kebabCase(value: string): string;
105
+ /**
106
+ * 转为下划线命名:`"FooBar"` → `"foo_bar"`,`"XMLParser"` → `"xml_parser"`。
107
+ */
108
+ declare function snakeCase(value: string): string;
109
+ /**
110
+ * 截断字符串到指定长度;放不下后缀时退化为纯截断。
111
+ *
112
+ * - `maxLength` 向下取整,`<= 0` 返回空串;
113
+ * - 原文长度不超过 `maxLength` 时原样返回;
114
+ * - `suffix.length >= maxLength` 时只截断、不追加后缀;
115
+ * - 返回值长度始终不超过 `maxLength`。
116
+ */
117
+ declare function cutString(value: string, maxLength: number, suffix?: string): string;
118
+ /**
119
+ * 清理字符串:可选去除首尾空白、可选删除换行符。
120
+ *
121
+ * `trimWhitespace` 为 `true`(默认)时调用 `trim()`;`removeNewlines` 为
122
+ * `true`(默认)时删除 `\r` 与 `\n`。非字符串输入返回空串。
123
+ */
124
+ declare function cleanString(value: string, trimWhitespace?: boolean, removeNewlines?: boolean): string;
125
+ /**
126
+ * 去除 HTML 标签,返回纯文本。
127
+ *
128
+ * 依次移除注释、`<script>` / `<style>` 块和其余标签,最后 `trim`。
129
+ * 实现为纯正则(不依赖 `DOMParser`),HTML 实体(如 `&amp;`)不会被解码。
130
+ */
131
+ declare function stripHtml(value: string): string;
132
+ /**
133
+ * 敏感信息脱敏:自动识别手机号、邮箱、身份证号、固定电话、车牌号与姓名。
134
+ *
135
+ * 识别时先移除空格、`-`、`()` 等分隔符;未命中任何格式时按姓名规则处理。
136
+ * 规则:
137
+ * - 手机号(`1[3-9]` 开头 11 位):保留前 3 后 4,中间 `****`;
138
+ * - 邮箱:`@` 前保留最多 3 位,其余用 `***` 替代,域名保留;
139
+ * - 身份证(15 位或 17 位 + 数字 / `X`):保留前 6 后 4,中间 `*`;
140
+ * - 固定电话(7~8 位,或 `0` 开头 10~12 位):保留前 3 后 4;
141
+ * - 车牌号(省份简称 + 字母 + 5~6 位字母数字):保留前 2 后 2;
142
+ * - 姓名:1 字 → `*`;2 字 → 姓 + `*`;3 字 → 姓 + `*` + 末字;
143
+ * 更长的姓名按长度保留首尾字符。
144
+ */
145
+ declare function maskSensitive(value: string | number): string;
146
+
147
+ /**
148
+ * 数字工具:范围限制、按精度舍入与区间判断。
149
+ */
150
+ /**
151
+ * 把数字限制在 `[min, max]` 闭区间内;`min > max` 抛 `RangeError`。
152
+ *
153
+ * `value` 为 `NaN` 时按 `Math.max` / `Math.min` 语义返回 `NaN`。
154
+ */
155
+ declare function rangeClamp(value: number, min: number, max: number): number;
156
+ /**
157
+ * 按指定小数位数四舍五入。
158
+ *
159
+ * 精度必须是 0 到 100 的整数,否则抛 `RangeError`;`.5` 按 `Math.round`
160
+ * 语义向正无穷方向舍入(`-2.5` → `-2`)。受 IEEE-754 浮点表示影响,
161
+ * `1.005` 这类值可能舍入到 `1`。
162
+ *
163
+ * `value` 接受数字或数字字符串;`NaN`、`±Infinity`、非数字字符串等
164
+ * 无法参与运算的值一律返回 `0`。
165
+ */
166
+ declare function toRound(value: number | string, precision?: number): number;
167
+ /**
168
+ * 按指定小数位数向下舍入(`Math.floor` 语义)。
169
+ *
170
+ * 精度必须是 0 到 100 的整数,否则抛 `RangeError`。
171
+ * 与 `toRound` 相同,受 IEEE-754 浮点表示影响,非数字输入返回 `0`。
172
+ */
173
+ declare function toFloor(value: number | string, precision?: number): number;
174
+ /**
175
+ * 按指定小数位数向上舍入(`Math.ceil` 语义)。
176
+ *
177
+ * 精度必须是 0 到 100 的整数,否则抛 `RangeError`。
178
+ * 与 `toRound` 相同,受 IEEE-754 浮点表示影响,非数字输入返回 `0`。
179
+ */
180
+ declare function toCeil(value: number | string, precision?: number): number;
181
+ /**
182
+ * 判断数字是否落在 `[min, max]` 闭区间内;`min > max` 抛 `RangeError`,
183
+ * `NaN` 永远返回 `false`。
184
+ */
185
+ declare function inRange(value: number, min: number, max: number): boolean;
186
+ /**
187
+ * 将数字或数字字符串格式化为固定小数位数的字符串,不足补 0、超出四舍五入。
188
+ *
189
+ * `precision` 必须是 0 到 100 的整数,否则抛 `RangeError`;非数字输入
190
+ * 原样转成字符串返回(如 `"abc"` → `"abc"`)。
191
+ */
192
+ declare function toFixed(value: number | string, precision?: number): string;
193
+
194
+ /**
195
+ * 对象工具:深拷贝与深合并。
196
+ */
197
+ /**
198
+ * 深拷贝对象 / 数组,返回与源数据无共享引用的新值。
199
+ *
200
+ * 支持循环引用、`Date`、`RegExp`、`Map`、`Set`、包装对象与 `Object.create(null)`;
201
+ * 保留原型链;函数按引用原样返回(不克隆函数体)。类型化数组、`ArrayBuffer`
202
+ * 等未被特殊处理的宿主对象按普通对象处理,不保证可用。
203
+ */
204
+ declare function deepClone<T>(value: T): T;
205
+ /**
206
+ * 深度合并普通对象,返回新对象,不修改任何入参。
207
+ *
208
+ * 后传入的属性覆盖先传入的;只有**两侧都是普通对象**时才递归合并,
209
+ * 数组、`Date`、`Map`、`Set` 等值整体覆盖(并深拷贝)。没有参数时返回 `{}`。
210
+ * 值为 `null` / 非对象的入参会被忽略;`__proto__` 键会被跳过,防止原型污染。
211
+ */
212
+ declare function deepMerge<T extends Record<PropertyKey, unknown>>(...sources: Array<Partial<T>>): T;
213
+
214
+ /**
215
+ * 格式化工具:金额、大写人民币、字节数与 K / W 展示。
216
+ */
217
+ /**
218
+ * 金额格式化:千分位分组,固定保留 2 位小数(四舍五入)。
219
+ *
220
+ * 默认添加人民币前缀 `¥` 与后缀 `元`;非数字按 `0` 处理。负数保留负号。
221
+ *
222
+ * @example
223
+ * formatMoney(1234567.89); // "¥1,234,567.89元"
224
+ * formatMoney(-1234.5, "", ""); // "-1,234.50"
225
+ */
226
+ declare function formatMoney(value: number | string, prefix?: string, suffix?: string): string;
227
+ /**
228
+ * 将金额转换为大写人民币。
229
+ *
230
+ * 金额先四舍五入到分,再按中文财务数字写法输出:
231
+ * `1234.56` → `"壹仟贰佰叁拾肆元伍角陆分"`;`0` → `"零元整"`,
232
+ * 负数加 `"负"` 前缀,`10` → `"拾元整"`。
233
+ *
234
+ * 支持到「仟亿」级(小于 1 万亿元);更大的金额返回空串。非数字、
235
+ * 非有限值同样返回空串。
236
+ *
237
+ * @example
238
+ * formatMoneyUpper(1234.56); // "壹仟贰佰叁拾肆元伍角陆分"
239
+ * formatMoneyUpper(-1.5); // "负壹元伍角"
240
+ */
241
+ declare function formatMoneyUpper(value: number | string): string;
242
+ /**
243
+ * 字节数格式化:自动选择 `B` / `KB` / `MB` / `GB` / `TB` / `PB` 单位。
244
+ *
245
+ * 每个单位按 1024 进位,使用向上舍入(`toCeil`)保留 `precision` 位小数,
246
+ * 默认 2 位;小于 1024 时直接输出字节数(负数原样输出,如 `"-5 B"`)。
247
+ * 非数字返回 `"0 B"`;超过 `PB` 的数值继续以 `PB` 表示。
248
+ *
249
+ * @example
250
+ * formatBytes(1024); // "1 KB"
251
+ * formatBytes(10241234); // "9.77 MB"
252
+ * formatBytes(1536, 0); // "2 KB"
253
+ */
254
+ declare function formatBytes(value: number | string, precision?: number): string;
255
+ /**
256
+ * 把数字格式化为千(`K`)或万(`W`)显示形式。
257
+ *
258
+ * 小于 1000 原样输出;1000~9999 用 `K`,10000 及以上用 `W`,
259
+ * 均按 `toFloor` 保留 `precision` 位小数(默认 1 位)。
260
+ * 小于 1(含负数、0)返回 `"0"`;非数字返回 `"-"`。
261
+ *
262
+ * @example
263
+ * formatKW(5632); // "5.6K"
264
+ * formatKW(20600); // "2W"
265
+ * formatKW(1032550, 1); // "103.2W"
266
+ */
267
+ declare function formatKW(value: number | string, precision?: number): string;
268
+
269
+ /**
270
+ * 随机工具:随机字符串、指定长度随机整数与区间随机数。
271
+ *
272
+ * 优先使用 `globalThis.crypto.getRandomValues` 生成均匀分布随机值;
273
+ * 运行环境不提供时退回 `Math.random`。注意:本模块与包内其它函数不同,
274
+ * 同一输入不保证同一输出,且 `Math.random` 路径不是密码学安全的。
275
+ */
276
+ /**
277
+ * 生成指定长度的随机字符串。
278
+ *
279
+ * 首字符不会取 ASCII 数字(除非 `chars` 中全部是数字);其余字符从
280
+ * `chars` 中等概率抽取。字符集默认包含大小写字母与数字。
281
+ *
282
+ * @param length 生成长度,必须是正整数,默认 16
283
+ * @param chars 可选字符集,至少 2 个字符
284
+ * @returns 随机字符串
285
+ * @throws {RangeError} `length` 不是正整数,或 `chars` 少于 2 个字符
286
+ * @throws {TypeError} `chars` 不是字符串
287
+ *
288
+ * @example
289
+ * randomString(); // 例如 "aB3dE9fG2hJ5kL7m"
290
+ * randomString(4, "01"); // 例如 "0101"
291
+ */
292
+ declare function randomString(length?: number, chars?: string): string;
293
+ /**
294
+ * 生成指定长度的随机整数,首位不为 0。
295
+ *
296
+ * 例如 `length = 4` 时结果落在 `1000`~`9999`。为保证结果是安全整数,
297
+ * 长度上限为 15 位。
298
+ *
299
+ * @param length 位数,必须是 `1` 到 `15` 的整数
300
+ * @returns 指定长度的随机整数
301
+ * @throws {RangeError} `length` 不是 `1..15` 的整数
302
+ *
303
+ * @example
304
+ * randomInteger(4); // 例如 5231
305
+ * randomInteger(1); // 1~9
306
+ */
307
+ declare function randomInteger(length: number): number;
308
+ /**
309
+ * 生成 `[min, max]` 闭区间内的随机整数。
310
+ *
311
+ * `min` / `max` 必须是安全整数,且 `max - min + 1` 也必须是安全整数
312
+ * (即区间不能大到无法在 `number` 中精确表示)。
313
+ *
314
+ * @param min 下界(包含)
315
+ * @param max 上界(包含)
316
+ * @returns `[min, max]` 内的随机整数
317
+ * @throws {RangeError} 边界不是安全整数、`min > max` 或区间过大
318
+ *
319
+ * @example
320
+ * randomInt(1, 10); // 1~10
321
+ * randomInt(-5, 5); // -5~5
322
+ */
323
+ declare function randomInt(min: number, max: number): number;
324
+ /**
325
+ * 生成 `[min, max]` 内的随机浮点数。
326
+ *
327
+ * 结果按 `precision` 位小数四舍五入,并限制回 `[min, max]` 闭区间,
328
+ * 因此舍入后仍不会越界。
329
+ *
330
+ * @param min 下界(包含)
331
+ * @param max 上界(包含,舍入后可能取到)
332
+ * @param precision 小数位数,必须是 `0..100` 的整数,默认 2
333
+ * @returns `[min, max]` 内的随机浮点数
334
+ * @throws {RangeError} 边界不是有限数字、`min > max`、区间过大或精度非法
335
+ *
336
+ * @example
337
+ * randomFloat(0, 1); // 例如 0.42
338
+ * randomFloat(1.5, 2.5, 0); // 2
339
+ */
340
+ declare function randomFloat(min: number, max: number, precision?: number): number;
341
+
342
+ /**
343
+ * 函数工具:防抖与节流。
344
+ *
345
+ * 这两个函数返回带内部状态的闭包,本身不产生模块级状态或求值副作用。
346
+ */
347
+ /**
348
+ * 防抖:在最后一次调用后延迟 `delay` 毫秒执行 `fn`,期间再次调用会重新计时。
349
+ *
350
+ * `delay` 默认 150;非有限值回退到默认值,负数按 0 处理。返回值保留调用时
351
+ * 的 `this` 与参数。
352
+ */
353
+ declare function debounce<T extends (...args: any[]) => any>(fn: T, delay?: number): (...args: Parameters<T>) => void;
354
+ /**
355
+ * 节流:立即执行首次调用,周期内的后续调用延迟到周期末尾执行最后一次。
356
+ *
357
+ * `delay` 默认 500;非有限值回退到默认值,负数按 0 处理。返回值保留调用时
358
+ * 的 `this` 与参数。
359
+ */
360
+ declare function throttle<T extends (...args: any[]) => any>(fn: T, delay?: number): (...args: Parameters<T>) => void;
361
+
362
+ /**
363
+ * 转换工具:把任意值转换为布尔值。
364
+ */
365
+ /**
366
+ * 把任意值转换为布尔值,常用于环境变量、查询参数等字符串配置。
367
+ *
368
+ * - 布尔值原样返回;
369
+ * - `null` / `undefined` / `""` / `0` / `NaN` / `0n` 为 `false`;
370
+ * - 其它非零数字为 `true`;
371
+ * - 字符串先 `trim` 再转小写,命中 `falseStrings` 为 `false`、命中
372
+ * `trueStrings` 为 `true`;都不命中(含仅空白字符串 `" "`)时为 `true`;
373
+ * - 包装对象递归取 `valueOf()`;函数、Symbol、普通对象为 `true`。
374
+ *
375
+ * `falseStrings` 的优先级高于 `trueStrings`。
376
+ */
377
+ declare function toBool(value: unknown, trueStrings?: readonly string[], falseStrings?: readonly string[]): boolean;
378
+
379
+ /**
380
+ * 文件工具:扩展名到 MIME 类型的映射。
381
+ */
382
+ /**
383
+ * 根据文件扩展名获取 MIME 类型。
384
+ *
385
+ * 扩展名大小写不敏感,允许带前导点(`".png"` 与 `"PNG"` 等价);
386
+ * 未收录或非字符串输入返回空串。扩展名与 MIME 的对应关系以 `EXT_MIME_MAP`
387
+ * 为准,不存在的扩展名不会猜测。
388
+ */
389
+ declare function fileExtToMime(ext: string): string;
390
+
391
+ export { assertArray, assertNumber, assertPrecision, assertRangeNumber, assertString, camelCase, capitalize, cleanString, cutString, debounce, deepClone, deepMerge, fileExtToMime, formatBytes, formatKW, formatMoney, formatMoneyUpper, inRange, isChinaIdCard, isChinaMobile, isChinaUSCC, isEmail, isEmpty, isHttpUrl, isNumeric, isPlainObject, kebabCase, maskSensitive, pascalCase, randomFloat, randomInt, randomInteger, randomString, rangeClamp, snakeCase, stripHtml, throttle, toBool, toCeil, toFixed, toFloor, toRound };