@pmun/utils 0.2.3 → 0.3.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/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ import { Dayjs, QUnitType, OpUnitType, ManipulateType } from 'dayjs';
9
9
  * @param array 原始数组
10
10
  * @param item 要移除的项
11
11
  * @returns 移除指定项后的新数组,不会修改原始数组
12
+ * @group Array
12
13
  * @example
13
14
  * ```ts
14
15
  * const numbers = [1, 2, 3, 4, 5]
@@ -25,6 +26,7 @@ declare function remove<T>(array: T[], item: T): T[];
25
26
  * 数组去重,移除数组中的重复元素
26
27
  * @param array 原始数组
27
28
  * @returns 去重后的新数组,保持原始顺序
29
+ * @group Array
28
30
  * @example
29
31
  * ```ts
30
32
  * const numbers = [1, 2, 2, 3, 3, 4, 5, 5]
@@ -41,6 +43,7 @@ declare function unique<T>(array: T[]): T[];
41
43
  * @param array 原始数组
42
44
  * @param size 每个块的大小,必须为正整数
43
45
  * @returns 二维数组,每个子数组最多包含 size 个元素
46
+ * @group Array
44
47
  * @example
45
48
  * ```ts
46
49
  * const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
@@ -56,6 +59,7 @@ declare function chunk<T>(array: T[], size: number): T[][];
56
59
  * 获取数组中的最后一个元素
57
60
  * @param array 数组
58
61
  * @returns 最后一个元素,如果数组为空则返回 undefined
62
+ * @group Array
59
63
  * @example
60
64
  * ```ts
61
65
  * const numbers = [1, 2, 3, 4, 5]
@@ -70,6 +74,7 @@ declare function last<T>(array: T[]): T | undefined;
70
74
  * 获取数组中的第一个元素
71
75
  * @param array 数组
72
76
  * @returns 第一个元素,如果数组为空则返回 undefined
77
+ * @group Array
73
78
  * @example
74
79
  * ```ts
75
80
  * const numbers = [1, 2, 3, 4, 5]
@@ -84,6 +89,7 @@ declare function first<T>(array: T[]): T | undefined;
84
89
  * 随机打乱数组元素顺序
85
90
  * @param array 原始数组
86
91
  * @returns 打乱后的新数组,不会修改原始数组
92
+ * @group Array
87
93
  * @example
88
94
  * ```ts
89
95
  * const numbers = [1, 2, 3, 4, 5]
@@ -97,6 +103,7 @@ declare function shuffle<T>(array: T[]): T[];
97
103
  * 从数组中随机选择一个元素
98
104
  * @param array 数组
99
105
  * @returns 随机选择的元素,如果数组为空则返回 undefined
106
+ * @group Array
100
107
  * @example
101
108
  * ```ts
102
109
  * const fruits = ['苹果', '香蕉', '橙子', '梨', '葡萄']
@@ -113,6 +120,7 @@ declare function sample<T>(array: T[]): T | undefined;
113
120
  * @param a 第一个数组
114
121
  * @param b 第二个数组
115
122
  * @returns 如果两个数组长度相同且对应位置的元素全部相等则返回 true,否则返回 false
123
+ * @group Array
116
124
  * @example
117
125
  * ```ts
118
126
  * isEqual([1, 2, 3], [1, 2, 3]) // true
@@ -131,6 +139,7 @@ declare function isEqual<T>(a: T[], b: T[]): boolean;
131
139
  * @param array 原始数组
132
140
  * @param keyFn 用于生成分组键的函数,接收数组元素并返回用作分组键的值
133
141
  * @returns 分组后的对象,键为分组键,值为对应的元素数组
142
+ * @group Array
134
143
  * @example
135
144
  * ```ts
136
145
  * const people = [
@@ -169,6 +178,7 @@ declare function groupBy<T, K extends string | number | symbol>(array: T[], keyF
169
178
  * @param config.valueKey - 选项值的字段名 (默认为 'value')
170
179
  * @returns 添加了"全部"选项的新数组
171
180
  *
181
+ * @group Array
172
182
  * @example
173
183
  * ```ts
174
184
  * // 基本用法
@@ -214,6 +224,7 @@ declare function appendUniversalOption<T extends Record<string, any>, V = any>(o
214
224
  * @param deleteOldKeys - 是否删除旧属性(默认 `true`)
215
225
  * @returns 处理后的树形结构数组
216
226
  *
227
+ * @group Array
217
228
  * @example
218
229
  * const tree = [
219
230
  * { id: 1, name: 'Node 1', children: [...] }
@@ -230,6 +241,7 @@ declare function renameTreeNodes(tree: any[], renameMap: Record<string, string>,
230
241
  * @param childKey - 子节点的键名(默认为 `'children'`)
231
242
  * @returns 转换后的树形结构数组
232
243
  *
244
+ * @group Array
233
245
  * @example
234
246
  * // 重命名 `name` 为 `label`,并添加 `isLeaf` 属性
235
247
  * const transformedTree = transformTree(tree, (node, children) => ({
@@ -248,7 +260,7 @@ type KeysMatching<T, V> = {
248
260
  * @param arr - 原始数组
249
261
  * @param key - 数组对象键
250
262
  * @returns 对应键的对象
251
- *
263
+ * @group Array
252
264
  * @example
253
265
  * ```ts
254
266
  * const arr = [{ key: 'tom', name: '汤姆' }, { key: 'jack', name: '杰克' }]
@@ -260,11 +272,44 @@ type KeysMatching<T, V> = {
260
272
  * ```
261
273
  */
262
274
  declare function arrayToObject<T>(arr: T[], key: KeysMatching<T, string | number>): Record<string, T>;
275
+ /**
276
+ * 替换数组数据中指定字段的 `&nbsp;` 为不换行空格
277
+ *
278
+ * @param {Array<Record<string, any>>} arr - 数组
279
+ * @param {string} key - 需要处理的字段名
280
+ * @returns {Array<Record<string, any>>} 处理后的数据数组
281
+ *
282
+ * @group String
283
+ * @example
284
+ * ```ts
285
+ * // 基本用法
286
+ * const data = [
287
+ * { name: 'John&nbsp;Doe', age: 30 },
288
+ * { name: 'Jane&nbsp;&nbsp;Smith', age: 25 }
289
+ * ]
290
+ * const result = arrayReplaceNBSP(data, 'name')
291
+ * // 结果: [
292
+ * // { name: 'John Doe', age: 30 },
293
+ * // { name: 'Jane Smith', age: 25 }
294
+ * // ]
295
+ *
296
+ * // 空数组情况
297
+ * const emptyData = []
298
+ * const result = arrayReplaceNBSP(emptyData, 'name')
299
+ * // 结果: []
300
+ * ```
301
+ */
302
+ declare function arrayReplaceNBSP<T extends Record<string, string | number | boolean | object>>(arr: T[], key: string): T[];
263
303
 
304
+ /**
305
+ * 表示日期的各种类型,可以是日期对象、日期字符串或时间戳
306
+ */
307
+ type DateLike = Date | string | number;
264
308
  /**
265
309
  * 创建 dayjs 对象
266
310
  * @param date 日期参数,可以是日期对象、时间戳或日期字符串
267
311
  * @returns dayjs 对象
312
+ * @group Date
268
313
  * @example
269
314
  * ```ts
270
315
  * createDate() // 当前日期时间
@@ -272,12 +317,41 @@ declare function arrayToObject<T>(arr: T[], key: KeysMatching<T, string | number
272
317
  * createDate(1684123456000) // 时间戳
273
318
  * ```
274
319
  */
275
- declare function createDate(date?: string | number | Date | Dayjs): Dayjs;
320
+ declare function createDate(date?: DateLike | Dayjs): Dayjs;
321
+ /**
322
+ * 判断时间戳是否为毫秒级时间戳
323
+ * @param value 要检查的值
324
+ * @returns 如果是毫秒级时间戳则返回 true,否则返回 false
325
+ * @group Date
326
+ * @example
327
+ * ```ts
328
+ * isMillisecondTimestamp(1673740800000) // true,13位数字
329
+ * isMillisecondTimestamp(1673740800) // false,10位数字,秒级时间戳
330
+ * isMillisecondTimestamp('1673740800000') // false, 字符串不是时间戳
331
+ * isMillisecondTimestamp(new Date()) // false,日期对象不是时间戳
332
+ * ```
333
+ */
334
+ declare function isMillisecondTimestamp(value: unknown): boolean;
335
+ /**
336
+ * 转换为 dayjs 可接收的参数格式
337
+ * @param value 日期参数,可以是日期对象、时间戳(秒或毫秒)或日期字符串
338
+ * @returns 转换后的参数,如果是秒级时间戳则转为毫秒级,其他类型保持不变
339
+ * @group Date
340
+ * @example
341
+ * ```ts
342
+ * convertToDayjsParam(1673740800) // 1673740800000,秒转为毫秒
343
+ * convertToDayjsParam(1673740800000) // 1673740800000,毫秒保持不变
344
+ * convertToDayjsParam(new Date()) // Date对象,保持不变
345
+ * convertToDayjsParam('2023-01-15') // '2023-01-15',字符串保持不变
346
+ * ```
347
+ */
348
+ declare function convertToDayjsParam(value: DateLike): DateLike;
276
349
  /**
277
350
  * 格式化日期为指定格式的字符串
278
351
  * @param date 日期对象、时间戳或日期字符串
279
- * @param format 格式字符串,支持的占位符请参考 dayjs 文档
352
+ * @param format 格式字符串,支持的占位符请参考 [dayjs 文档](https://day.js.org/docs/zh-CN/durations/format#%E6%94%AF%E6%8C%81%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%8D%A0%E4%BD%8D%E7%AC%A6%E5%88%97%E8%A1%A8)
280
353
  * @returns 格式化后的日期字符串
354
+ * @group Date
281
355
  * @example
282
356
  * ```ts
283
357
  * formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss') // "2023-05-16 14:30:45"
@@ -285,10 +359,24 @@ declare function createDate(date?: string | number | Date | Dayjs): Dayjs;
285
359
  * formatDate(1684123456000, 'MM/DD/YYYY') // "05/15/2023"
286
360
  * ```
287
361
  */
288
- declare function formatDate(date: Date | string | number, format?: string): string;
362
+ declare function formatDate(date: DateLike, format?: string): string;
363
+ /**
364
+ * 将日期格式化为完整的时间字符串(YYYY-MM-DD HH:mm:ss)
365
+ * @param date 日期对象、时间戳或日期字符串
366
+ * @returns 格式为 YYYY-MM-DD HH:mm:ss 的日期时间字符串
367
+ * @group Date
368
+ * @example
369
+ * ```ts
370
+ * formatFullTime(new Date()) // "2023-05-16 14:30:45"
371
+ * formatFullTime('2023-05-15') // "2023-05-15 00:00:00"
372
+ * formatFullTime(1684123456) // "2023-05-15 10:30:56"(秒级时间戳会被自动转换)
373
+ * ```
374
+ */
375
+ declare function formatFullTime(date: DateLike): string;
289
376
  /**
290
377
  * 获取当前日期时间的时间戳
291
378
  * @returns 当前时间戳(毫秒)
379
+ * @group Date
292
380
  * @example
293
381
  * ```ts
294
382
  * now() // 例如: 1684123456789
@@ -300,6 +388,7 @@ declare function now(): number;
300
388
  * @param dateStr 日期字符串
301
389
  * @returns 日期对象
302
390
  * @throws 如果日期格式无效,抛出 TypeError
391
+ * @group Date
303
392
  * @example
304
393
  * ```ts
305
394
  * parseDate('2023-05-15') // Date 对象: Mon May 15 2023 00:00:00
@@ -314,6 +403,7 @@ declare function parseDate(dateStr: string): Date;
314
403
  * @param date2 第二个日期
315
404
  * @param unit 计量单位,默认为 'day',可以是 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'
316
405
  * @returns 两个日期之间的差值,正数表示 date1 晚于 date2,负数表示 date1 早于 date2
406
+ * @group Date
317
407
  * @example
318
408
  * ```ts
319
409
  * diff('2023-05-15', '2023-05-10') // 5(相差5天)
@@ -321,13 +411,14 @@ declare function parseDate(dateStr: string): Date;
321
411
  * diff('2023-05-15 08:00', '2023-05-15 06:00', 'hour') // 2(相差2小时)
322
412
  * ```
323
413
  */
324
- declare function diff(date1: Date | string | number, date2: Date | string | number, unit?: QUnitType | OpUnitType): number;
414
+ declare function diff(date1: DateLike, date2: DateLike, unit?: QUnitType | OpUnitType): number;
325
415
  /**
326
416
  * 向日期添加指定时间
327
417
  * @param date 原始日期
328
418
  * @param amount 要添加的数量,可以为负数
329
419
  * @param unit 时间单位,默认为 'day',可以是 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'
330
420
  * @returns 添加后的新日期对象
421
+ * @group Date
331
422
  * @example
332
423
  * ```ts
333
424
  * add(new Date('2023-05-15'), 2, 'day') // Date 对象: Wed May 17 2023
@@ -335,24 +426,26 @@ declare function diff(date1: Date | string | number, date2: Date | string | numb
335
426
  * add('2023-05-15 12:00', 30, 'minute') // Date 对象: Mon May 15 2023 12:30:00
336
427
  * ```
337
428
  */
338
- declare function add(date: Date | string | number, amount: number, unit?: ManipulateType): Date;
429
+ declare function add(date: DateLike, amount: number, unit?: ManipulateType): Date;
339
430
  /**
340
431
  * 向日期添加指定天数
341
432
  * @param date 原始日期
342
433
  * @param days 要添加的天数(可以为负数)
343
434
  * @returns 添加天数后的新日期对象
435
+ * @group Date
344
436
  * @example
345
437
  * ```ts
346
438
  * addDays(new Date('2023-05-15'), 5) // Date 对象: Sat May 20 2023
347
439
  * addDays('2023-05-15', -3) // Date 对象: Fri May 12 2023
348
440
  * ```
349
441
  */
350
- declare function addDays(date: Date | string | number, days: number): Date;
442
+ declare function addDays(date: DateLike, days: number): Date;
351
443
  /**
352
444
  * 向日期添加指定月数
353
445
  * @param date 原始日期
354
446
  * @param months 要添加的月数(可以为负数)
355
447
  * @returns 添加月数后的新日期对象
448
+ * @group Date
356
449
  * @example
357
450
  * ```ts
358
451
  * addMonths(new Date('2023-05-15'), 2) // Date 对象: Sat Jul 15 2023
@@ -360,12 +453,13 @@ declare function addDays(date: Date | string | number, days: number): Date;
360
453
  * addMonths('2023-01-15', -3) // Date 对象: Wed Oct 15 2022
361
454
  * ```
362
455
  */
363
- declare function addMonths(date: Date | string | number, months: number): Date;
456
+ declare function addMonths(date: DateLike, months: number): Date;
364
457
  /**
365
458
  * 向日期添加指定年数
366
459
  * @param date 原始日期
367
460
  * @param years 要添加的年数(可以为负数)
368
461
  * @returns 添加年数后的新日期对象
462
+ * @group Date
369
463
  * @example
370
464
  * ```ts
371
465
  * addYears(new Date('2023-05-15'), 1) // Date 对象: Wed May 15 2024
@@ -373,12 +467,13 @@ declare function addMonths(date: Date | string | number, months: number): Date;
373
467
  * addYears('2024-02-29', 1) // Date 对象: Fri Feb 28 2025(注意闰年自动调整)
374
468
  * ```
375
469
  */
376
- declare function addYears(date: Date | string | number, years: number): Date;
470
+ declare function addYears(date: DateLike, years: number): Date;
377
471
  /**
378
472
  * 获取指定日期是一周中的第几天
379
473
  * @param date 日期
380
474
  * @param startOnMonday 是否从周一开始计算(默认为 false,即从周日开始)
381
475
  * @returns 一周中的第几天(0-6),周日为 0,周六为 6;如果 startOnMonday 为 true,则周一为 0,周日为 6
476
+ * @group Date
382
477
  * @example
383
478
  * ```ts
384
479
  * getDayOfWeek(new Date('2023-05-15')) // 1(周一,从周日开始算是第1天)
@@ -387,13 +482,14 @@ declare function addYears(date: Date | string | number, years: number): Date;
387
482
  * getDayOfWeek('2023-05-14', true) // 6(周日,从周一开始算是第6天)
388
483
  * ```
389
484
  */
390
- declare function getDayOfWeek(date: Date | string | number, startOnMonday?: boolean): number;
485
+ declare function getDayOfWeek(date: DateLike, startOnMonday?: boolean): number;
391
486
  /**
392
487
  * 检查日期是否在指定范围内
393
488
  * @param date 要检查的日期
394
489
  * @param startDate 范围起始日期
395
490
  * @param endDate 范围结束日期
396
491
  * @returns 如果日期在指定范围内(不包括边界)则返回 true,否则返回 false
492
+ * @group Date
397
493
  * @example
398
494
  * ```ts
399
495
  * isDateInRange('2023-05-15', '2023-05-10', '2023-05-20') // true
@@ -401,12 +497,13 @@ declare function getDayOfWeek(date: Date | string | number, startOnMonday?: bool
401
497
  * isDateInRange('2023-05-15', '2023-05-10', '2023-05-15') // false(不包括结束日期)
402
498
  * ```
403
499
  */
404
- declare function isDateInRange(date: Date | string | number, startDate: Date | string | number, endDate: Date | string | number): boolean;
500
+ declare function isDateInRange(date: DateLike, startDate: DateLike, endDate: DateLike): boolean;
405
501
  /**
406
502
  * 获取指定月份的天数
407
503
  * @param year 年份
408
504
  * @param month 月份(0-11),0 表示一月,11 表示十二月
409
505
  * @returns 该月的天数
506
+ * @group Date
410
507
  * @example
411
508
  * ```ts
412
509
  * getDaysInMonth(2023, 1) // 28(2023年2月有28天)
@@ -420,19 +517,21 @@ declare function getDaysInMonth(year: number, month: number): number;
420
517
  * @param date 日期
421
518
  * @param baseDate 基准日期,默认为当前时间
422
519
  * @returns 相对时间描述,如"几分钟前"、"几天后"等
520
+ * @group Date
423
521
  * @example
424
522
  * ```ts
425
523
  * fromNow(new Date(Date.now() - 5 * 60 * 1000)) // "5分钟前"
426
- * fromNow(new Date(Date.now() + 24 * 60 * 60 * 1000)) // "1天后"
524
+ * fromNow(new Date(Date.now() + 24 * 60 * 60 * 1000)) // "1天内"
427
525
  * fromNow('2023-01-01', '2023-01-05') // "4天前"
428
526
  * ```
429
527
  */
430
- declare function fromNow(date: Date | string | number, baseDate?: Date | string | number): string;
528
+ declare function fromNow(date: DateLike, baseDate?: DateLike): string;
431
529
  /**
432
530
  * 获取日期的开始时间
433
531
  * @param date 日期
434
532
  * @param unit 单位,可以是 'year', 'month', 'week', 'day', 'hour', 'minute', 'second'
435
533
  * @returns 单位开始时间的日期对象
534
+ * @group Date
436
535
  * @example
437
536
  * ```ts
438
537
  * startOf(new Date('2023-05-15 15:30:45'), 'day') // Date 对象: Mon May 15 2023 00:00:00
@@ -440,12 +539,13 @@ declare function fromNow(date: Date | string | number, baseDate?: Date | string
440
539
  * startOf('2023-05-15 15:30:45', 'hour') // Date 对象: Mon May 15 2023 15:00:00
441
540
  * ```
442
541
  */
443
- declare function startOf(date: Date | string | number, unit: OpUnitType): Date;
542
+ declare function startOf(date: DateLike, unit: OpUnitType): Date;
444
543
  /**
445
544
  * 获取日期的结束时间
446
545
  * @param date 日期
447
546
  * @param unit 单位,可以是 'year', 'month', 'week', 'day', 'hour', 'minute', 'second'
448
547
  * @returns 单位结束时间的日期对象
548
+ * @group Date
449
549
  * @example
450
550
  * ```ts
451
551
  * endOf(new Date('2023-05-15 15:30:45'), 'day') // Date 对象: Mon May 15 2023 23:59:59.999
@@ -453,11 +553,12 @@ declare function startOf(date: Date | string | number, unit: OpUnitType): Date;
453
553
  * endOf('2023-05-15 15:30:45', 'hour') // Date 对象: Mon May 15 2023 15:59:59.999
454
554
  * ```
455
555
  */
456
- declare function endOf(date: Date | string | number, unit: OpUnitType): Date;
556
+ declare function endOf(date: DateLike, unit: OpUnitType): Date;
457
557
  /**
458
558
  * 格式化日期为人类友好的格式
459
559
  * @param date 日期
460
560
  * @returns 人类友好的日期描述,如"今天 HH:mm"、"昨天 HH:mm"、"明天 HH:mm"或"YYYY-MM-DD HH:mm"
561
+ * @group Date
461
562
  * @example
462
563
  * ```ts
463
564
  * formatHumanReadable(new Date()) // "今天 15:30"
@@ -466,7 +567,7 @@ declare function endOf(date: Date | string | number, unit: OpUnitType): Date;
466
567
  * formatHumanReadable('2023-01-01') // "2023-01-01 00:00"
467
568
  * ```
468
569
  */
469
- declare function formatHumanReadable(date: Date | string | number): string;
570
+ declare function formatHumanReadable(date: DateLike): string;
470
571
 
471
572
  /**
472
573
  * @module 类型检查
@@ -476,6 +577,7 @@ declare function formatHumanReadable(date: Date | string | number): string;
476
577
  * 检查值是否为字符串类型
477
578
  * @param val 要检查的值
478
579
  * @returns 如果是字符串则返回 true,否则返回 false
580
+ * @group Is
479
581
  * @example
480
582
  * ```ts
481
583
  * isString('hello') // true
@@ -488,6 +590,7 @@ declare function isString(val: unknown): val is string;
488
590
  * 检查值是否为数字类型
489
591
  * @param val 要检查的值
490
592
  * @returns 如果是数字则返回 true,否则返回 false(NaN 会返回 false)
593
+ * @group Is
491
594
  * @example
492
595
  * ```ts
493
596
  * isNumber(123) // true
@@ -502,6 +605,7 @@ declare function isNumber(val: unknown): val is number;
502
605
  * 检查值是否为布尔类型
503
606
  * @param val 要检查的值
504
607
  * @returns 如果是布尔值则返回 true,否则返回 false
608
+ * @group Is
505
609
  * @example
506
610
  * ```ts
507
611
  * isBoolean(true) // true
@@ -516,6 +620,7 @@ declare function isBoolean(val: unknown): val is boolean;
516
620
  * 检查值是否为函数类型
517
621
  * @param val 要检查的值
518
622
  * @returns 如果是函数则返回 true,否则返回 false
623
+ * @group Is
519
624
  * @example
520
625
  * ```ts
521
626
  * isFunction(() => {}) // true
@@ -530,6 +635,7 @@ declare function isFunction(val: unknown): val is ((...args: any[]) => any);
530
635
  * 检查值是否为对象类型(不包括 null)
531
636
  * @param val 要检查的值
532
637
  * @returns 如果是对象则返回 true,否则返回 false
638
+ * @group Is
533
639
  * @example
534
640
  * ```ts
535
641
  * isObject({}) // true
@@ -545,6 +651,7 @@ declare function isObject(val: unknown): val is Record<any, any>;
545
651
  * 检查值是否为数组类型
546
652
  * @param val 要检查的值
547
653
  * @returns 如果是数组则返回 true,否则返回 false
654
+ * @group Is
548
655
  * @example
549
656
  * ```ts
550
657
  * isArray([]) // true
@@ -559,6 +666,7 @@ declare function isArray(val: unknown): val is any[];
559
666
  * 检查值是否为日期类型
560
667
  * @param val 要检查的值
561
668
  * @returns 如果是日期对象则返回 true,否则返回 false
669
+ * @group Is
562
670
  * @example
563
671
  * ```ts
564
672
  * isDate(new Date()) // true
@@ -571,6 +679,7 @@ declare function isDate(val: unknown): val is Date;
571
679
  * 检查值是否为正则表达式
572
680
  * @param val 要检查的值
573
681
  * @returns 如果是正则表达式则返回 true,否则返回 false
682
+ * @group Is
574
683
  * @example
575
684
  * ```ts
576
685
  * isRegExp(/abc/) // true
@@ -584,6 +693,7 @@ declare function isRegExp(val: unknown): val is RegExp;
584
693
  * 检查值是否为 Promise
585
694
  * @param val 要检查的值
586
695
  * @returns 如果是 Promise 则返回 true,否则返回 false
696
+ * @group Is
587
697
  * @example
588
698
  * ```ts
589
699
  * isPromise(Promise.resolve()) // true
@@ -598,6 +708,7 @@ declare function isPromise<T = any>(val: unknown): val is Promise<T>;
598
708
  * 检查值是否为 Map
599
709
  * @param val 要检查的值
600
710
  * @returns 如果是 Map 则返回 true,否则返回 false
711
+ * @group Is
601
712
  * @example
602
713
  * ```ts
603
714
  * isMap(new Map()) // true
@@ -610,6 +721,7 @@ declare function isMap<K = any, V = any>(val: unknown): val is Map<K, V>;
610
721
  * 检查值是否为 Set
611
722
  * @param val 要检查的值
612
723
  * @returns 如果是 Set 则返回 true,否则返回 false
724
+ * @group Is
613
725
  * @example
614
726
  * ```ts
615
727
  * isSet(new Set()) // true
@@ -622,6 +734,7 @@ declare function isSet<T = any>(val: unknown): val is Set<T>;
622
734
  * 检查值是否为 Symbol
623
735
  * @param val 要检查的值
624
736
  * @returns 如果是 Symbol 则返回 true,否则返回 false
737
+ * @group Is
625
738
  * @example
626
739
  * ```ts
627
740
  * isSymbol(Symbol('foo')) // true
@@ -634,6 +747,7 @@ declare function isSymbol(val: unknown): val is symbol;
634
747
  * 检查值是否为原始类型(string、number、boolean、symbol、bigint、null、undefined)
635
748
  * @param val 要检查的值
636
749
  * @returns 如果是原始类型则返回 true,否则返回 false
750
+ * @group Is
637
751
  * @example
638
752
  * ```ts
639
753
  * isPrimitive('hello') // true
@@ -653,6 +767,7 @@ declare function isPrimitive(val: unknown): boolean;
653
767
  * 检查值是否为 undefined
654
768
  * @param val 要检查的值
655
769
  * @returns 如果是 undefined 则返回 true,否则返回 false
770
+ * @group Is
656
771
  * @example
657
772
  * ```ts
658
773
  * isUndefined(undefined) // true
@@ -666,6 +781,7 @@ declare function isUndefined(val: unknown): val is undefined;
666
781
  * 检查值是否为 null
667
782
  * @param val 要检查的值
668
783
  * @returns 如果是 null 则返回 true,否则返回 false
784
+ * @group Is
669
785
  * @example
670
786
  * ```ts
671
787
  * isNull(null) // true
@@ -679,6 +795,7 @@ declare function isNull(val: unknown): val is null;
679
795
  * 检查值是否为 null 或 undefined
680
796
  * @param val 要检查的值
681
797
  * @returns 如果是 null 或 undefined 则返回 true,否则返回 false
798
+ * @group Is
682
799
  * @example
683
800
  * ```ts
684
801
  * isNullOrUndefined(null) // true
@@ -693,6 +810,7 @@ declare function isNullOrUndefined(val: unknown): val is null | undefined;
693
810
  * 检查对象是否为空对象(没有自身可枚举属性)
694
811
  * @param val 要检查的值
695
812
  * @returns 如果是空对象则返回 true,否则返回 false;如果不是对象类型则返回 false
813
+ * @group Is
696
814
  * @example
697
815
  * ```ts
698
816
  * isEmptyObject({}) // true
@@ -708,6 +826,7 @@ declare function isEmptyObject(val: unknown): boolean;
708
826
  * 检查值是否为空(null、undefined、空字符串、空数组或空对象)
709
827
  * @param val 要检查的值
710
828
  * @returns 如果是空值则返回 true,否则返回 false
829
+ * @group Is
711
830
  * @example
712
831
  * ```ts
713
832
  * isEmpty(null) // true
@@ -726,6 +845,7 @@ declare function isEmpty(val: unknown): boolean;
726
845
  * 检查值是否为 NaN
727
846
  * @param value 要检查的值
728
847
  * @returns 如果值是 NaN 则返回 true,否则返回 false
848
+ * @group Is
729
849
  * @example
730
850
  * ```ts
731
851
  * isNaN(NaN) // true
@@ -742,6 +862,7 @@ declare function isNaN(value: unknown): boolean;
742
862
  * @param {unknown} value - 要检查的值
743
863
  * @returns {boolean} 如果值是普通对象则返回 true,否则返回 false
744
864
  *
865
+ * @group Is
745
866
  * @example
746
867
  * ```ts
747
868
  * isPlainObject({}) // true
@@ -762,6 +883,7 @@ declare function isPlainObject(value: unknown): value is Record<string, any>;
762
883
  * @param num 要处理的数字
763
884
  * @param precision 小数位数,默认为0(整数)
764
885
  * @returns 四舍五入后的数字
886
+ * @group Number
765
887
  * @example
766
888
  * ```ts
767
889
  * round(3.1415) // 3
@@ -776,6 +898,7 @@ declare function round(num: number, precision?: number): number;
776
898
  * @param num 要格式化的数字
777
899
  * @param locale 区域设置,默认为浏览器默认区域
778
900
  * @returns 格式化后的字符串
901
+ * @group Number
779
902
  * @example
780
903
  * ```ts
781
904
  * formatThousands(1234567) // '1,234,567'(根据浏览器默认区域可能有所不同)
@@ -793,6 +916,7 @@ declare function formatThousands(num: number, locale?: string): string;
793
916
  * @param options.minimumFractionDigits 最小小数位数,默认为 2
794
917
  * @param options.maximumFractionDigits 最大小数位数,默认为 2
795
918
  * @returns 格式化后的货币字符串
919
+ * @group Number
796
920
  * @example
797
921
  * ```ts
798
922
  * formatCurrency(1234.56) // '¥1,234.56'
@@ -813,6 +937,7 @@ declare function formatCurrency(value: number, options?: {
813
937
  * @param min 最小值
814
938
  * @param max 最大值
815
939
  * @returns 在指定范围内的数字:如果小于最小值返回最小值,如果大于最大值返回最大值
940
+ * @group Number
816
941
  * @example
817
942
  * ```ts
818
943
  * clamp(5, 0, 10) // 5 - 在范围内,保持不变
@@ -826,6 +951,7 @@ declare function clamp(num: number, min: number, max: number): number;
826
951
  * @param min 最小值(包含)
827
952
  * @param max 最大值(包含)
828
953
  * @returns 指定范围内的随机整数
954
+ * @group Number
829
955
  * @example
830
956
  * ```ts
831
957
  * randomInt(1, 10) // 返回 1 到 10 之间的随机整数,包括 1 和 10
@@ -838,6 +964,7 @@ declare function randomInt(min: number, max: number): number;
838
964
  * 检查一个数字是否为偶数
839
965
  * @param num 要检查的数字
840
966
  * @returns 如果是偶数则返回 true,否则返回 false
967
+ * @group Number
841
968
  * @example
842
969
  * ```ts
843
970
  * isEven(2) // true
@@ -851,6 +978,7 @@ declare function isEven(num: number): boolean;
851
978
  * 检查一个数字是否为奇数
852
979
  * @param num 要检查的数字
853
980
  * @returns 如果是奇数则返回 true,否则返回 false
981
+ * @group Number
854
982
  * @example
855
983
  * ```ts
856
984
  * isOdd(3) // true
@@ -866,6 +994,7 @@ declare function isOdd(num: number): boolean;
866
994
  * @param total 总值
867
995
  * @param precision 结果保留的小数位数,默认为2
868
996
  * @returns 百分比值,如果总值为零则返回 0
997
+ * @group Number
869
998
  * @example
870
999
  * ```ts
871
1000
  * percentage(25, 100) // 25
@@ -880,6 +1009,7 @@ declare function percentage(value: number, total: number, precision?: number): n
880
1009
  * @param num 要转换的数值
881
1010
  * @param fractionDigits 小数位数,默认为2
882
1011
  * @returns 转换后的字符串,如果值大于等于10000则转为"万"单位
1012
+ * @group Number
883
1013
  * @example
884
1014
  * ```ts
885
1015
  * formatNumberWithTenThousand(1234) // '1234'
@@ -900,7 +1030,7 @@ declare function formatNumberWithTenThousand(num: number, fractionDigits?: numbe
900
1030
  * @param {object} obj - 需要检查的对象
901
1031
  * @param {string | symbol} prop - 需要检查的属性键
902
1032
  * @returns {boolean} 如果对象具有该自有属性,则返回 true,否则返回 false
903
- *
1033
+ * @group Object
904
1034
  * @example
905
1035
  * ```ts
906
1036
  * const obj = { name: 'Tom', age: 25 }
@@ -913,6 +1043,7 @@ declare function hasOwnProp(obj: object, prop: string | symbol): boolean;
913
1043
  * 深拷贝对象,支持基本类型、数组、对象、日期和正则表达式
914
1044
  * @param obj 要拷贝的对象
915
1045
  * @returns 深拷贝后的对象,与原对象完全独立
1046
+ * @group Object
916
1047
  * @example
917
1048
  * ```ts
918
1049
  * const original = { a: 1, b: { c: 2 }, d: [1, 2, 3], e: new Date() }
@@ -933,6 +1064,7 @@ declare function deepClone<T>(obj: T): T;
933
1064
  * @param path 属性路径,如 'user.address.street'
934
1065
  * @param defaultValue 默认值,当路径不存在时返回
935
1066
  * @returns 路径对应的值,如果路径不存在则返回默认值
1067
+ * @group Object
936
1068
  * @example
937
1069
  * ```ts
938
1070
  * const obj = { user: { profile: { name: 'Tom', age: 25 }, roles: ['admin'] } }
@@ -950,10 +1082,13 @@ declare function get<T = any>(obj: Record<string, any>, path: string, defaultVal
950
1082
  * @param obj 原始对象
951
1083
  * @param keys 要选择的键数组
952
1084
  * @returns 包含指定键的新对象
1085
+ * @group Object
953
1086
  * @example
954
1087
  * ```ts
1088
+ * @group Object
955
1089
  * const user = { id: 1, name: 'Tom', age: 25, email: 'tom@example.com' }
956
1090
  *
1091
+ * @group Object
957
1092
  * pick(user, ['name', 'email']) // { name: 'Tom', email: 'tom@example.com' }
958
1093
  * pick(user, ['name', 'gender']) // { name: 'Tom' }(不存在的键会被忽略)
959
1094
  * pick(user, []) // {}(空数组返回空对象)
@@ -965,6 +1100,7 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
965
1100
  * @param obj 原始对象
966
1101
  * @param keys 要排除的键数组
967
1102
  * @returns 不包含指定键的新对象
1103
+ * @group Object
968
1104
  * @example
969
1105
  * ```ts
970
1106
  * const user = { id: 1, name: 'Tom', age: 25, password: '123456' }
@@ -979,6 +1115,7 @@ declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T,
979
1115
  * 将对象转换为 URL 查询字符串
980
1116
  * @param obj 要转换的对象
981
1117
  * @returns 格式化后的查询字符串(不包含前导?)
1118
+ * @group Object
982
1119
  * @example
983
1120
  * ```ts
984
1121
  * objectToQueryString({ name: 'Tom', age: 25 }) // 'name=Tom&age=25'
@@ -992,6 +1129,7 @@ declare function objectToQueryString(obj: Record<string, any>): string;
992
1129
  * 合并多个对象,后面的对象的属性会覆盖前面的
993
1130
  * @param objects 要合并的对象数组
994
1131
  * @returns 合并后的新对象
1132
+ * @group Object
995
1133
  * @example
996
1134
  * ```ts
997
1135
  * merge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
@@ -1005,6 +1143,7 @@ declare function merge<T extends Record<string, any>>(...objects: T[]): T;
1005
1143
  * 深度合并多个对象,会递归合并嵌套对象
1006
1144
  * @param objects 要合并的对象数组
1007
1145
  * @returns 深度合并后的新对象
1146
+ * @group Object
1008
1147
  * @example
1009
1148
  * ```ts
1010
1149
  * deepMerge({ a: { x: 1 } }, { a: { y: 2 } }) // { a: { x: 1, y: 2 } }
@@ -1020,6 +1159,7 @@ declare function deepMerge(...objects: Record<string, any>[]): Record<string, an
1020
1159
  * @param keysArray 要保留的键名数组
1021
1160
  * @param keyMapping 可选的键名映射对象,格式为 { 原键名: 新键名 }
1022
1161
  * @returns 返回一个新对象,其中只包含原对象中匹配的键值对,并根据映射重命名键
1162
+ * @group Object
1023
1163
  * @example
1024
1164
  * ```ts
1025
1165
  * const originalObject = { name: "John", age: 30, gender: "male", country: "USA" }
@@ -1036,7 +1176,7 @@ declare function filterObjectByKeys(originalObject: Record<string, any>, keysArr
1036
1176
  *
1037
1177
  * @param {number} ms - 需要延迟的毫秒数
1038
1178
  * @returns {Promise<void>} 返回一个在指定时间后resolve的Promise
1039
- *
1179
+ * @group Promise
1040
1180
  * @example
1041
1181
  * ```ts
1042
1182
  * // 延迟2秒
@@ -1060,6 +1200,7 @@ declare function delay(ms: number): Promise<void>;
1060
1200
  * 将字符串首字母转为大写
1061
1201
  * @param str 输入字符串
1062
1202
  * @returns 首字母大写后的字符串
1203
+ * @group String
1063
1204
  * @example
1064
1205
  * ```ts
1065
1206
  * capitalize('hello') // 'Hello'
@@ -1072,6 +1213,7 @@ declare function capitalize(str: string): string;
1072
1213
  * 将驼峰命名转换为短横线命名(kebab-case)
1073
1214
  * @param str 驼峰命名的字符串
1074
1215
  * @returns 短横线命名的字符串
1216
+ * @group String
1075
1217
  * @example
1076
1218
  * ```ts
1077
1219
  * camelToKebab('helloWorld') // 'hello-world'
@@ -1085,6 +1227,7 @@ declare function camelToKebab(str: string): string;
1085
1227
  * 将短横线命名(kebab-case)转换为驼峰命名(camelCase)
1086
1228
  * @param str 短横线命名的字符串
1087
1229
  * @returns 驼峰命名的字符串
1230
+ * @group String
1088
1231
  * @example
1089
1232
  * ```ts
1090
1233
  * kebabToCamel('hello-world') // 'helloWorld'
@@ -1100,6 +1243,7 @@ declare function kebabToCamel(str: string): string;
1100
1243
  * @param length 截取的最大长度,默认为 50
1101
1244
  * @param ellipsis 省略号字符,默认为'...'
1102
1245
  * @returns 截取后的字符串,如果原字符串长度小于等于截取长度,则返回原字符串
1246
+ * @group String
1103
1247
  * @example
1104
1248
  * ```ts
1105
1249
  * truncate('这是一个很长的字符串', 5) // '这是...'
@@ -1113,6 +1257,7 @@ declare function truncate(str: string, length?: number, ellipsis?: string): stri
1113
1257
  * @param length 字符串长度
1114
1258
  * @param chars 可选的字符集,默认包含大小写字母和数字
1115
1259
  * @returns 生成的随机字符串
1260
+ * @group String
1116
1261
  * @example
1117
1262
  * ```ts
1118
1263
  * randomString(5) // 例如: 'aB9cD'
@@ -1125,6 +1270,7 @@ declare function randomString(length: number, chars?: string): string;
1125
1270
  * 将字符串中的 HTML 特殊字符转义,防止 XSS 攻击
1126
1271
  * @param html 包含 HTML 的字符串
1127
1272
  * @returns 转义后的安全字符串
1273
+ * @group String
1128
1274
  * @example
1129
1275
  * ```ts
1130
1276
  * escapeHtml('<div>Hello & World</div>') // '&lt;div&gt;Hello &amp; World&lt;/div&gt;'
@@ -1136,6 +1282,7 @@ declare function escapeHtml(html: string): string;
1136
1282
  * 检查字符串是否为有效的 URL
1137
1283
  * @param url 要检查的 URL 字符串
1138
1284
  * @returns 如果是有效的 URL 则返回 true,否则返回 false
1285
+ * @group String
1139
1286
  * @example
1140
1287
  * ```ts
1141
1288
  * isValidUrl('https://example.com') // true
@@ -1149,9 +1296,12 @@ declare function isValidUrl(url: string): boolean;
1149
1296
  * 检查字符串是否为有效的电子邮件地址
1150
1297
  * @param email 要检查的电子邮件地址
1151
1298
  * @returns 如果是有效的电子邮件地址则返回 true,否则返回 false
1299
+ * @group String
1152
1300
  * @example
1153
1301
  * ```ts
1302
+ * @group String
1154
1303
  * isValidEmail('user@example.com') // true
1304
+ * @group String
1155
1305
  * isValidEmail('user.name+tag@example.co.uk') // true
1156
1306
  * isValidEmail('invalid@email') // false,缺少顶级域名
1157
1307
  * isValidEmail('not an email') // false
@@ -1162,6 +1312,7 @@ declare function isValidEmail(email: string): boolean;
1162
1312
  * 检查字符串是否为空或只包含空白字符
1163
1313
  * @param str 要检查的字符串
1164
1314
  * @returns 如果字符串为空或只包含空白字符,则返回 true
1315
+ * @group String
1165
1316
  * @example
1166
1317
  * ```ts
1167
1318
  * isEmptyString('') // true
@@ -1175,6 +1326,7 @@ declare function isEmptyString(str: string): boolean;
1175
1326
  * 确保值具有 rpx 单位,主要用于小程序/uni-app 样式处理
1176
1327
  * @param val 需要转化的值,可以是数字或字符串
1177
1328
  * @returns 转化后带有 rpx 单位的字符串,如果输入不是数字则原样返回
1329
+ * @group String
1178
1330
  * @example
1179
1331
  * ```ts
1180
1332
  * ensureRpxUnit(100) // '100rpx'
@@ -1185,45 +1337,21 @@ declare function isEmptyString(str: string): boolean;
1185
1337
  */
1186
1338
  declare function ensureRpxUnit(val: string | number): string;
1187
1339
  /**
1188
- * 替换表格数据中指定字段的 &nbsp; 为不换行空格
1340
+ * 替换字符串中的 `&nbsp;` 为不换行空格
1189
1341
  *
1190
- * @param {Array<Record<string, any>>} tableData - 表格数据数组或Vue ref
1191
- * @param {string} key - 需要处理的字段名
1192
- * @returns {Array<Record<string, any>>} 处理后的表格数据数组
1342
+ * @param {string} str - 字符串
1343
+ * @returns {string} 处理后的字符串
1193
1344
  *
1345
+ * @group String
1194
1346
  * @example
1195
1347
  * ```ts
1196
1348
  * // 基本用法
1197
- * const data = [
1198
- * { name: 'John&nbsp;Doe', age: 30 },
1199
- * { name: 'Jane&nbsp;&nbsp;Smith', age: 25 }
1200
- * ]
1201
- * const result = replaceNBSP(data, 'name')
1202
- * // 结果: [
1203
- * // { name: 'John Doe', age: 30 },
1204
- * // { name: 'Jane Smith', age: 25 }
1205
- * // ]
1206
- *
1207
- * // 使用ref包装的数据 (在Vue中使用)
1208
- * const refData = ref([
1209
- * { desc: 'Product&nbsp;Info', price: 99 },
1210
- * { desc: 'Service&nbsp;&nbsp;Details', price: 50 }
1211
- * ])
1212
- * const result = replaceNBSP(refData, 'desc')
1213
- * // 结果: [
1214
- * // { desc: 'Product Info', price: 99 },
1215
- * // { desc: 'Service Details', price: 50 }
1216
- * // ]
1217
- *
1218
- * // 空数组情况
1219
- * const emptyData = []
1220
- * const result = replaceNBSP(emptyData, 'name')
1221
- * // 结果: []
1349
+ * replaceNBSP('John&nbsp;Doe') // 'John Doe'
1350
+ * replaceNBSP('Jane&nbsp;&nbsp;Smith') // 'Jane Smith'
1351
+ * replaceNBSP('Smith') // 'Smith'
1222
1352
  * ```
1223
1353
  */
1224
- declare function replaceNBSP<T extends Record<string, string | number | boolean | object>>(tableData: T[] | {
1225
- value: T[];
1226
- }, key: string): T[];
1354
+ declare function replaceNBSP(str?: string): string;
1227
1355
 
1228
1356
  /**
1229
1357
  * 将对象转换为URL查询字符串
@@ -1231,7 +1359,7 @@ declare function replaceNBSP<T extends Record<string, string | number | boolean
1231
1359
  * @deprecated 请使用 objectToQueryString 函数代替,它在 object 模块中。该函数将在下一个主要版本中移除。
1232
1360
  * @param {Record<string, any>} params - 需要转换的对象
1233
1361
  * @returns {string} 转换后的查询字符串,如果有参数则以?开头
1234
- *
1362
+ * @group Url
1235
1363
  * @example
1236
1364
  * ```ts
1237
1365
  * // 基本用法
@@ -1253,4 +1381,4 @@ declare function replaceNBSP<T extends Record<string, string | number | boolean
1253
1381
  */
1254
1382
  declare function getQueryStringify(params: Record<string, any> | null | undefined): string;
1255
1383
 
1256
- export { add, addDays, addMonths, addYears, appendUniversalOption, arrayToObject, camelToKebab, capitalize, chunk, clamp, createDate, deepClone, deepMerge, delay, diff, endOf, ensureRpxUnit, escapeHtml, filterObjectByKeys, first, formatCurrency, formatDate, formatHumanReadable, formatNumberWithTenThousand, formatThousands, fromNow, get, getDayOfWeek, getDaysInMonth, getQueryStringify, groupBy, hasOwnProp, isArray, isBoolean, isDate, isDateInRange, isEmpty, isEmptyObject, isEmptyString, isEqual, isEven, isFunction, isMap, isNaN, isNull, isNullOrUndefined, isNumber, isObject, isOdd, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isUndefined, isValidEmail, isValidUrl, kebabToCamel, last, merge, now, objectToQueryString, omit, parseDate, percentage, pick, randomInt, randomString, remove, renameTreeNodes, replaceNBSP, round, sample, shuffle, startOf, transformTree, truncate, unique };
1384
+ export { type DateLike, add, addDays, addMonths, addYears, appendUniversalOption, arrayReplaceNBSP, arrayToObject, camelToKebab, capitalize, chunk, clamp, convertToDayjsParam, createDate, deepClone, deepMerge, delay, diff, endOf, ensureRpxUnit, escapeHtml, filterObjectByKeys, first, formatCurrency, formatDate, formatFullTime, formatHumanReadable, formatNumberWithTenThousand, formatThousands, fromNow, get, getDayOfWeek, getDaysInMonth, getQueryStringify, groupBy, hasOwnProp, isArray, isBoolean, isDate, isDateInRange, isEmpty, isEmptyObject, isEmptyString, isEqual, isEven, isFunction, isMap, isMillisecondTimestamp, isNaN, isNull, isNullOrUndefined, isNumber, isObject, isOdd, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isUndefined, isValidEmail, isValidUrl, kebabToCamel, last, merge, now, objectToQueryString, omit, parseDate, percentage, pick, randomInt, randomString, remove, renameTreeNodes, replaceNBSP, round, sample, shuffle, startOf, transformTree, truncate, unique };