pen-it 1.0.8 → 1.0.9
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 +6 -1
- package/dist/array/index.d.ts +0 -68
- package/dist/browser/index.d.ts +0 -54
- package/dist/control/index.d.ts +0 -16
- package/dist/cookie/index.d.ts +0 -15
- package/dist/copy/index.d.ts +0 -20
- package/dist/format/index.d.ts +0 -117
- package/dist/index.cjs +1 -1000
- package/dist/index.js +1 -917
- package/dist/is/index.d.ts +0 -138
- package/dist/storage/index.d.ts +0 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -578,7 +578,12 @@ import { isArray, formatFull, deepClone, unique } from 'pen-it'
|
|
|
578
578
|
|
|
579
579
|
## 更新日志
|
|
580
580
|
|
|
581
|
-
### v1.0.
|
|
581
|
+
### v1.0.9
|
|
582
|
+
|
|
583
|
+
- **构建优化** — rolldown 开启 `minify: true`压缩 JS/CJS(注释/空白移除 + 变量名缩短)
|
|
584
|
+
- **类型声明优化** — 移除 `.d.ts` 中冗余的 JSDoc 注释
|
|
585
|
+
|
|
586
|
+
### v1.0.7 & v1.0.8
|
|
582
587
|
|
|
583
588
|
- **体积优化** — 移除JSDoc `@example` 示例注释(共 294 行),减少包体积
|
|
584
589
|
- **文档** — README 底部新增更新日志模块
|
package/dist/array/index.d.ts
CHANGED
|
@@ -1,80 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set 去重
|
|
3
|
-
* @param arr - 数组
|
|
4
|
-
* @returns 去重后的数组
|
|
5
|
-
*/
|
|
6
1
|
export declare const unique: <T>(arr: T[]) => T[];
|
|
7
|
-
/**
|
|
8
|
-
* 对象数组按 key 去重
|
|
9
|
-
* @param arr - 对象数组
|
|
10
|
-
* @param key - 用于去重判定的键名
|
|
11
|
-
* @returns 去重后的数组
|
|
12
|
-
*/
|
|
13
2
|
export declare const uniqueByKey: <T extends Record<string, any>>(arr: T[], key: keyof T) => T[];
|
|
14
|
-
/**
|
|
15
|
-
* 数值升序
|
|
16
|
-
* @param arr - 数值数组
|
|
17
|
-
* @returns 升序排序后的新数组
|
|
18
|
-
*/
|
|
19
3
|
export declare const sortNumAsc: (arr: number[]) => number[];
|
|
20
|
-
/**
|
|
21
|
-
* 数值降序
|
|
22
|
-
* @param arr - 数值数组
|
|
23
|
-
* @returns 降序排序后的新数组
|
|
24
|
-
*/
|
|
25
4
|
export declare const sortNumDesc: (arr: number[]) => number[];
|
|
26
|
-
/**
|
|
27
|
-
* 按对象属性排序
|
|
28
|
-
* @param arr - 对象数组
|
|
29
|
-
* @param key - 用于排序的属性名
|
|
30
|
-
* @param order - 排序方向,"asc" 升序 / "desc" 降序,默认 "asc"
|
|
31
|
-
* @returns 排序后的新数组
|
|
32
|
-
*/
|
|
33
5
|
export declare const sortByKey: <T extends Record<string, any>>(arr: T[], key: keyof T, order?: "asc" | "desc") => T[];
|
|
34
|
-
/**
|
|
35
|
-
* 类数组转数组
|
|
36
|
-
* @param arrayLike - 类数组对象(如 NodeList、arguments)
|
|
37
|
-
* @returns 转换后的数组
|
|
38
|
-
*/
|
|
39
6
|
export declare const toArray: <T>(arrayLike: ArrayLike<T>) => T[];
|
|
40
|
-
/**
|
|
41
|
-
* 合并多个数组
|
|
42
|
-
* @param arrays - 一个或多个数组
|
|
43
|
-
* @returns 合并后的新数组
|
|
44
|
-
*/
|
|
45
7
|
export declare const mergeArrays: <T>(...arrays: T[][]) => T[];
|
|
46
|
-
/**
|
|
47
|
-
* 将多维数组扁平化到指定层级
|
|
48
|
-
* @param arr - 多维数组
|
|
49
|
-
* @param depth - 扁平化深度,默认 1(仅展开一层)。传 Infinity 可完全扁平化为一维
|
|
50
|
-
* @returns 扁平化后的数组
|
|
51
|
-
*/
|
|
52
8
|
export declare const flatten: <T>(arr: any[], depth?: number) => T[];
|
|
53
|
-
/**
|
|
54
|
-
* 在对象数组中按 key-value 查找第一个匹配项
|
|
55
|
-
* @param arr - 对象数组
|
|
56
|
-
* @param key - 要匹配的键名
|
|
57
|
-
* @param value - 要匹配的键值
|
|
58
|
-
* @returns 第一个匹配的对象,无匹配则返回 undefined
|
|
59
|
-
*/
|
|
60
9
|
export declare const arrFind: <T extends Record<string, any>>(arr: T[], key: keyof T, value: T[keyof T]) => T | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* 将对象数组按指定属性分组
|
|
63
|
-
* @param arr - 对象数组
|
|
64
|
-
* @param key - 用于分组的属性名
|
|
65
|
-
* @returns 以属性值为键、对应数组为值的对象
|
|
66
|
-
*/
|
|
67
10
|
export declare const groupBy: <T extends Record<string, any>>(arr: T[], key: keyof T) => Record<string, T[]>;
|
|
68
|
-
/**
|
|
69
|
-
* 移除对象中值为空(null / undefined / 空字符串)的属性
|
|
70
|
-
* @param obj - 待过滤的对象
|
|
71
|
-
* @returns 过滤后的新对象
|
|
72
|
-
*/
|
|
73
11
|
export declare const filterEmptyValues: <T extends Record<string, any>>(obj: T) => Partial<T>;
|
|
74
|
-
/**
|
|
75
|
-
* 根据长度和映射函数快速生成数组
|
|
76
|
-
* @param length - 数组长度
|
|
77
|
-
* @param mapFn - 映射函数,接收索引返回元素值,默认为返回索引
|
|
78
|
-
* @returns 生成的数组
|
|
79
|
-
*/
|
|
80
12
|
export declare const createRange: <T = number>(length: number, mapFn?: (index: number) => T) => T[];
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,64 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 获取 URL 参数对象
|
|
3
|
-
* @param url - URL 字符串,默认使用当前页面地址
|
|
4
|
-
* @returns 参数键值对对象
|
|
5
|
-
*/
|
|
6
1
|
export declare const getUrlParams: (url?: string) => Record<string, string>;
|
|
7
|
-
/**
|
|
8
|
-
* 获取单个 URL 参数
|
|
9
|
-
* @param key - 参数名
|
|
10
|
-
* @param url - URL 字符串,默认使用当前页面地址
|
|
11
|
-
* @returns 参数值,不存在则返回 null
|
|
12
|
-
*/
|
|
13
2
|
export declare const getUrlParam: (key: string, url?: string) => string | null;
|
|
14
|
-
/**
|
|
15
|
-
* 对象转 URL 参数字符串
|
|
16
|
-
* @param params - 参数键值对对象,值为 null/undefined 的项会被过滤
|
|
17
|
-
* @returns URL 参数字符串(不含 ? 前缀)
|
|
18
|
-
*/
|
|
19
3
|
export declare const toQueryString: (params: Record<string, any>) => string;
|
|
20
|
-
/**
|
|
21
|
-
* 复制文本到剪贴板
|
|
22
|
-
* 优先使用 Clipboard API,失败时降级为 execCommand
|
|
23
|
-
* @param text - 要复制的文本
|
|
24
|
-
* @returns 复制成功返回 true,失败返回 false
|
|
25
|
-
*/
|
|
26
4
|
export declare const copyToClipboard: (text: string) => Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* 下载文件(Blob)
|
|
29
|
-
* @param content - 文件内容
|
|
30
|
-
* @param filename - 文件名
|
|
31
|
-
* @param mimeType - MIME 类型,默认 "text/plain"
|
|
32
|
-
*/
|
|
33
5
|
export declare const downloadFile: (content: string | BlobPart, filename: string, mimeType?: string) => void;
|
|
34
|
-
/**
|
|
35
|
-
* 导出 JSON 为文件
|
|
36
|
-
* @param data - 要导出的数据
|
|
37
|
-
* @param filename - 文件名,默认 "data.json"
|
|
38
|
-
*/
|
|
39
6
|
export declare const exportJSON: (data: any, filename?: string) => void;
|
|
40
|
-
/**
|
|
41
|
-
* 滚动到顶部
|
|
42
|
-
* @param behavior - 滚动行为,"smooth" 平滑 / "auto" 瞬间,默认 "smooth"
|
|
43
|
-
*/
|
|
44
7
|
export declare const scrollToTop: (behavior?: ScrollBehavior) => void;
|
|
45
|
-
/**
|
|
46
|
-
* 滚动到底部
|
|
47
|
-
* @param behavior - 滚动行为,"smooth" 平滑 / "auto" 瞬间,默认 "smooth"
|
|
48
|
-
*/
|
|
49
8
|
export declare const scrollToBottom: (behavior?: ScrollBehavior) => void;
|
|
50
|
-
/**
|
|
51
|
-
* 监听页面滚动(requestAnimationFrame 节流)
|
|
52
|
-
* @param callback - 滚动回调,接收当前 scrollY 值
|
|
53
|
-
* @returns 清理函数,调用后移除事件监听
|
|
54
|
-
*/
|
|
55
9
|
export declare const onScroll: (callback: (scrollY: number) => void) => () => void;
|
|
56
|
-
/**
|
|
57
|
-
* 监听目标元素是否进入/离开可视区域
|
|
58
|
-
* @param target - 目标 DOM 元素
|
|
59
|
-
* @param onEnter - 元素进入可视区域时的回调
|
|
60
|
-
* @param onLeave - 元素离开可视区域时的回调(可选)
|
|
61
|
-
* @param options - IntersectionObserver 配置项
|
|
62
|
-
* @returns 清理函数,调用后停止观察
|
|
63
|
-
*/
|
|
64
10
|
export declare const observeIntersection: (target: Element, onEnter: (entry: IntersectionObserverEntry) => void, onLeave?: (entry: IntersectionObserverEntry) => void, options?: IntersectionObserverInit) => () => void;
|
package/dist/control/index.d.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 防抖 —— 在事件被触发 n 秒后再执行,如果 n 秒内再次触发则重新计时
|
|
3
|
-
* @param fn - 需要防抖的函数
|
|
4
|
-
* @param delay - 延迟时间(毫秒),默认 300
|
|
5
|
-
* @param options.leading - 首次调用是否立即执行,默认 false
|
|
6
|
-
* @param options.trailing - 停止调用后是否延迟执行,默认 true
|
|
7
|
-
* @returns 防抖后的函数,附带 cancel 方法
|
|
8
|
-
*/
|
|
9
1
|
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, delay?: number, { leading, trailing }?: {
|
|
10
2
|
leading?: boolean;
|
|
11
3
|
trailing?: boolean;
|
|
12
4
|
}) => ((...args: Parameters<T>) => void) & {
|
|
13
5
|
cancel: () => void;
|
|
14
6
|
};
|
|
15
|
-
/**
|
|
16
|
-
* 节流 —— 固定间隔内最多执行一次,超出频率的调用被忽略
|
|
17
|
-
* @param fn - 需要节流的函数
|
|
18
|
-
* @param interval - 间隔时间(毫秒),默认 300
|
|
19
|
-
* @param options.leading - 首次调用是否立即执行,默认 true
|
|
20
|
-
* @param options.trailing - 最后一次调用后是否尾部执行,默认 true
|
|
21
|
-
* @returns 节流后的函数,附带 cancel 方法
|
|
22
|
-
*/
|
|
23
7
|
export declare const throttle: <T extends (...args: any[]) => any>(fn: T, interval?: number, { leading, trailing }?: {
|
|
24
8
|
leading?: boolean;
|
|
25
9
|
trailing?: boolean;
|
package/dist/cookie/index.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置 Cookie
|
|
3
|
-
* @param name - Cookie 名称
|
|
4
|
-
* @param value - Cookie 值
|
|
5
|
-
* @param days - 有效天数,默认 7 天
|
|
6
|
-
*/
|
|
7
1
|
export declare const setCookie: (name: string, value: string, days?: number) => void;
|
|
8
|
-
/**
|
|
9
|
-
* 获取 Cookie
|
|
10
|
-
* @param name - Cookie 名称
|
|
11
|
-
* @returns Cookie 值,不存在则返回 null
|
|
12
|
-
*/
|
|
13
2
|
export declare const getCookie: (name: string) => string | null;
|
|
14
|
-
/**
|
|
15
|
-
* 删除 Cookie
|
|
16
|
-
* @param name - Cookie 名称
|
|
17
|
-
*/
|
|
18
3
|
export declare const delCookie: (name: string) => void;
|
package/dist/copy/index.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 递归深拷贝
|
|
3
|
-
* 支持 Date、RegExp、Map、Set、Array、Object 以及循环引用
|
|
4
|
-
* @param obj - 要拷贝的值
|
|
5
|
-
* @param hash - 内部 WeakMap 用于处理循环引用,调用方无需传入
|
|
6
|
-
* @returns 深拷贝后的值
|
|
7
|
-
*/
|
|
8
1
|
export declare function deepClone<T>(obj: T, hash?: WeakMap<any, any>): T;
|
|
9
|
-
/**
|
|
10
|
-
* JSON 深拷贝
|
|
11
|
-
* 使用 JSON 序列化与反序列化实现,仅支持 JSON 安全的数据类型
|
|
12
|
-
* (不支持函数、undefined、Date、RegExp、Map、Set 等)
|
|
13
|
-
* @param obj - 要拷贝的 JSON 安全值
|
|
14
|
-
* @returns 深拷贝后的值
|
|
15
|
-
*/
|
|
16
2
|
export declare function deepCloneWithJSON<T>(obj: T): T;
|
|
17
|
-
/**
|
|
18
|
-
* 浅拷贝
|
|
19
|
-
* 仅拷贝第一层属性,嵌套对象仍共享引用
|
|
20
|
-
* @param obj - 要拷贝的对象或数组
|
|
21
|
-
* @returns 浅拷贝后的值
|
|
22
|
-
*/
|
|
23
3
|
export declare function shallowClone<T>(obj: T): T;
|
package/dist/format/index.d.ts
CHANGED
|
@@ -1,142 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 完整日期时间(年/月/日 时分秒)_ 斜杠
|
|
3
|
-
* @param date - Date 对象
|
|
4
|
-
* @returns 格式化后的完整日期时间字符串,如 "2026/06/03 14:30:45"
|
|
5
|
-
*/
|
|
6
1
|
export declare const formatFull: (date: Date) => string;
|
|
7
|
-
/**
|
|
8
|
-
* 完整日期时间(年-月-日 时分秒)_ 短横线
|
|
9
|
-
* @param date - Date 对象
|
|
10
|
-
* @returns 格式化后的完整日期时间字符串,如 "2026-06-03 14:30:45"
|
|
11
|
-
*/
|
|
12
2
|
export declare const formatFullReplace: (date: Date) => string;
|
|
13
|
-
/**
|
|
14
|
-
* 中文年月日
|
|
15
|
-
* @param date - Date 对象
|
|
16
|
-
* @returns 格式化后的中文日期字符串,如 "2026年6月3日"
|
|
17
|
-
*/
|
|
18
3
|
export declare const formatYMD: (date: Date) => string;
|
|
19
|
-
/**
|
|
20
|
-
* 星期几
|
|
21
|
-
* @param date - Date 对象
|
|
22
|
-
* @returns 中文星期字符串,如 "星期三"
|
|
23
|
-
*/
|
|
24
4
|
export declare const formatWeek: (date: Date) => string;
|
|
25
|
-
/**
|
|
26
|
-
* 货币格式化
|
|
27
|
-
* @param value - 数值
|
|
28
|
-
* @param options - 格式化选项
|
|
29
|
-
* @returns 格式化后的货币字符串
|
|
30
|
-
*/
|
|
31
5
|
export declare const formatRmb: (value: number, options: {
|
|
32
6
|
type: "zh-CN";
|
|
33
7
|
currency: "CNY";
|
|
34
8
|
}) => string;
|
|
35
|
-
/**
|
|
36
|
-
* 千位分隔符(数字格式化),中文(逗号分隔)
|
|
37
|
-
* @param value - 数值
|
|
38
|
-
* @returns 格式化后的千位分隔数字字符串
|
|
39
|
-
*/
|
|
40
9
|
export declare const formatNum: (value: number) => string;
|
|
41
|
-
/**
|
|
42
|
-
* 百分比格式化
|
|
43
|
-
* @param value - 百分比数值
|
|
44
|
-
* @param digit - 保留的小数位数,默认为 0
|
|
45
|
-
* @returns 格式化后的百分比字符串
|
|
46
|
-
*/
|
|
47
10
|
export declare const percentCN: (value: number, digit?: number) => string;
|
|
48
|
-
/**
|
|
49
|
-
* 紧凑计数法(大数简化)_ 英文缩写
|
|
50
|
-
* @param value - 数值
|
|
51
|
-
* @returns 格式化后的紧凑数字字符串(英文缩写)
|
|
52
|
-
*/
|
|
53
11
|
export declare const compactEN: (value: number) => string;
|
|
54
|
-
/**
|
|
55
|
-
* 紧凑计数法(大数简化)_ 中文缩写
|
|
56
|
-
* @param value - 数值
|
|
57
|
-
* @returns 格式化后的紧凑数字字符串(中文缩写)
|
|
58
|
-
*/
|
|
59
12
|
export declare const compactCN: (value: number) => string;
|
|
60
|
-
/**
|
|
61
|
-
* 带符号的正负数显示
|
|
62
|
-
* @param value - 数值
|
|
63
|
-
* @param digit - 保留的小数位数,默认为 0
|
|
64
|
-
* @returns 格式化后的带正负号的数值显示
|
|
65
|
-
*/
|
|
66
13
|
export declare const signed: (value: number, digit?: number) => string;
|
|
67
|
-
/**
|
|
68
|
-
* 手机号格式化脱敏 _ 隐藏中间 4 位数
|
|
69
|
-
* @param phone - 手机号码
|
|
70
|
-
* @returns 手机号格式化脱敏后的手机号
|
|
71
|
-
*/
|
|
72
14
|
export declare const maskPhone: (phone: string) => string;
|
|
73
|
-
/**
|
|
74
|
-
* 手机号格式化 _ 空格分隔
|
|
75
|
-
* @param phone - 手机号
|
|
76
|
-
* @returns 手机号空格格式化的手机号
|
|
77
|
-
*/
|
|
78
15
|
export declare const spacePhone: (phone: string) => string;
|
|
79
|
-
/**
|
|
80
|
-
* 每个单词首字母大写
|
|
81
|
-
* @param str - 字符串
|
|
82
|
-
* @returns 每个单词首字母大写后的字符串
|
|
83
|
-
*/
|
|
84
16
|
export declare const capitalize: (str: string) => string;
|
|
85
|
-
/**
|
|
86
|
-
* 短横线连接转小驼峰(kebab-case → camelCase)
|
|
87
|
-
* @param str - 字符串
|
|
88
|
-
* @returns 转换后的小驼峰字符串
|
|
89
|
-
*/
|
|
90
17
|
export declare const kebabToCamel: (str: string) => string;
|
|
91
|
-
/**
|
|
92
|
-
* 大驼峰或小驼峰 _ 转为 ‘-’ 短横线连接
|
|
93
|
-
* @param str - 字符串
|
|
94
|
-
* @returns 大驼峰或小驼峰命名格式化的字符串
|
|
95
|
-
*/
|
|
96
18
|
export declare const camelToKebab: (str: string) => string;
|
|
97
|
-
/**
|
|
98
|
-
* 超长文本截断
|
|
99
|
-
* @param str - 内容
|
|
100
|
-
* @param maxLength - 截断位置
|
|
101
|
-
* @param suffix - 自定义的替换截断后的内容
|
|
102
|
-
* @returns 超长文本截断后内容
|
|
103
|
-
*/
|
|
104
19
|
export declare const truncate: (str: string, maxLength: number, suffix?: string) => string;
|
|
105
|
-
/**
|
|
106
|
-
* 按字数截断(中文友好)
|
|
107
|
-
* @param str - 内容
|
|
108
|
-
* @param maxWords - 截断位置
|
|
109
|
-
* @param suffix - 自定义的替换截断后的内容
|
|
110
|
-
* @returns 超长文本截断后内容
|
|
111
|
-
*/
|
|
112
20
|
export declare const truncateByWords: (str: string, maxWords: number, suffix?: string) => string;
|
|
113
|
-
/**
|
|
114
|
-
* 去除所有空格 _ 前后中间
|
|
115
|
-
* @param str - 内容
|
|
116
|
-
* @returns 去除空格后的内容
|
|
117
|
-
*/
|
|
118
21
|
export declare const trimAll: (str: string) => string;
|
|
119
|
-
/**
|
|
120
|
-
* 下划线转驼峰(snake_case → camelCase)
|
|
121
|
-
* @param str - 字符串
|
|
122
|
-
* @returns 转换后的驼峰字符串
|
|
123
|
-
*/
|
|
124
22
|
export declare const toCamel: (str: string) => string;
|
|
125
|
-
/**
|
|
126
|
-
* 首字母大写
|
|
127
|
-
* @param str - 字符串
|
|
128
|
-
* @returns 首字母大写后的字符串
|
|
129
|
-
*/
|
|
130
23
|
export declare const firstUpper: (str: string) => string;
|
|
131
|
-
/**
|
|
132
|
-
* 首字母小写
|
|
133
|
-
* @param str - 字符串
|
|
134
|
-
* @returns 首字母小写后的字符串
|
|
135
|
-
*/
|
|
136
24
|
export declare const firstLower: (str: string) => string;
|
|
137
|
-
/**
|
|
138
|
-
* 反转字符串
|
|
139
|
-
* @param str - 字符串
|
|
140
|
-
* @returns 反转后的字符串
|
|
141
|
-
*/
|
|
142
25
|
export declare const reverse: (str: string) => string;
|