gzjs-utils 1.0.2-7.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.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 进度信息
3
+ */
4
+ export interface MD5ProgressInfo {
5
+ /** 已读取字节数 */
6
+ loaded: number;
7
+ /** 文件总字节数 */
8
+ total: number;
9
+ /** 进度百分比 (0-100) */
10
+ percent: number;
11
+ }
12
+ /**
13
+ * 文件 MD5 计算选项
14
+ */
15
+ export interface MD5FileOptions {
16
+ /** 分块大小,默认 4MB */
17
+ chunkSize?: number;
18
+ /** 进度回调函数 */
19
+ onProgress?: (info: MD5ProgressInfo) => void;
20
+ }
21
+ /**
22
+ * 文件输入类型:浏览器 File 对象或 Node.js 文件路径字符串
23
+ */
24
+ type MD5FileInput = File | string;
25
+ /**
26
+ * HMAC-MD5 加密,返回十六进制字符串
27
+ * @param key 密钥
28
+ * @param data 数据
29
+ * @returns 十六进制字符串格式的 HMAC-MD5 哈希值
30
+ */
31
+ export declare function hmac_md5(key: any, data: any): string;
32
+ /**
33
+ * MD5 工具类
34
+ */
35
+ declare const _MD5_: {
36
+ /**
37
+ * MD5 加密,返回十六进制字符串
38
+ * @param str 待加密的字符串
39
+ * @returns 十六进制字符串格式的 MD5 哈希值
40
+ */
41
+ encode(str: string): string;
42
+ /**
43
+ * HMAC-MD5 加密,返回十六进制字符串
44
+ * @param key 加密密钥
45
+ * @param str 加密内容
46
+ * @returns 十六进制字符串格式的 HMAC-MD5 哈希值
47
+ */
48
+ HmacMD5(key: string, str: string): string;
49
+ /**
50
+ * 计算文件 MD5 哈希(支持大文件流式计算)
51
+ * @param file 文件对象(浏览器)或文件路径(Node.js)
52
+ * @param options 可选配置:分块大小、进度回调
53
+ * @returns Promise<string> 返回哈希值(32 字符 hex)
54
+ * @example
55
+ * // Node.js
56
+ * const hash = await MD5.encodeFile('/path/to/file.zip', {
57
+ * onProgress: (p) => console.log(`${p.percent}%`)
58
+ * });
59
+ * // 浏览器
60
+ * const hash = await MD5.encodeFile(fileInput.files[0]);
61
+ */
62
+ encodeFile(file: MD5FileInput, options?: MD5FileOptions): Promise<string>;
63
+ };
64
+ export default _MD5_;
65
+ export declare type MD5 = typeof _MD5_;
@@ -0,0 +1,21 @@
1
+ export declare class AggregateError extends Error {
2
+ errors: any[];
3
+ constructor(errors: any[], message?: string);
4
+ }
5
+ export declare class _Promise {
6
+ private PromiseState;
7
+ private PromiseResult;
8
+ private callbacks;
9
+ private finallys;
10
+ constructor(executor: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void);
11
+ then(onResolved?: (value: any) => any, onRejected?: (reason: any) => any): _Promise;
12
+ catch(onRejected: (reason: any) => any): _Promise;
13
+ finally(onFinally?: () => any): _Promise;
14
+ static resolve(value: any): _Promise;
15
+ static reject(reason: any): _Promise;
16
+ static all(promises: Array<_Promise | Promise<any>>): _Promise;
17
+ static race(promises: Array<_Promise | Promise<any>>): _Promise;
18
+ static any(promises: Array<_Promise | Promise<any>>): _Promise;
19
+ }
20
+ export default _Promise;
21
+ export type PromiseType = typeof _Promise;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @description: the description Regexps
3
+ * @fileName: Regexps.ts
4
+ * @author: xiyuan-lgz
5
+ * @date: 2026-02-28 13:17:19
6
+ * @version: 1.0.0
7
+ */
8
+ export declare const _Regexps_: {
9
+ /**
10
+ * 空格 空白
11
+ */
12
+ SPACE: RegExp;
13
+ /**
14
+ * 左空白
15
+ */
16
+ SPACE_LEFT: RegExp;
17
+ /**
18
+ * 有空白
19
+ */
20
+ SPACE_RIGHT: RegExp;
21
+ /**
22
+ * //数字,至少1位
23
+ */
24
+ NUMERIC: RegExp;
25
+ /**
26
+ * //整数,支持正负数
27
+ */
28
+ INTEGER: RegExp;
29
+ /**
30
+ * //正整数,第一个数字是1-9
31
+ */
32
+ INTEGER_P: RegExp;
33
+ /**
34
+ * //非负整数,0或者正整数
35
+ */
36
+ INTEGER_N_N: RegExp;
37
+ /**
38
+ * //浮点值,支持多位小数点,支持正负数
39
+ */
40
+ FLOAT: RegExp;
41
+ /**
42
+ * //浮点值,支持多位小数
43
+ */
44
+ FLOAT_N_N: RegExp;
45
+ /**
46
+ * //标准元金额,支持0-2位小数,支持正负数
47
+ */
48
+ AMOUNT_2R: RegExp;
49
+ /**
50
+ * //固定元金额,两位小数,支持正负数
51
+ */
52
+ AMOUNT_2R_FIXED: RegExp;
53
+ /**
54
+ * //标准元金额,支持0-2位小数
55
+ */
56
+ AMOUNT_N_N_2R: RegExp;
57
+ /**
58
+ * //固定元金额,两位小数
59
+ */
60
+ AMOUNT_N_N_2R_FIXED: RegExp;
61
+ /**
62
+ * //字母
63
+ */
64
+ ALPHABAT: RegExp;
65
+ /**
66
+ * //大写字母
67
+ */
68
+ ALPHABAT_UPPER: RegExp;
69
+ /**
70
+ * //小写字母
71
+ */
72
+ ALPHABAT_LOWER: RegExp;
73
+ /**
74
+ * //小写字母或数字
75
+ */
76
+ ALPHA_LOWER_NUMERIC: RegExp;
77
+ /**
78
+ * //大写字母或数字
79
+ */
80
+ ALPHA_UPPER_NUMERIC: RegExp;
81
+ /**
82
+ * //大小写字母或数字
83
+ */
84
+ ALPHA_NUMERIC: RegExp;
85
+ /**
86
+ * //大小写字母或数字,开头必须为字母
87
+ */
88
+ ALPHA_NUMERIC_PA: RegExp;
89
+ /**
90
+ * //双字节
91
+ */
92
+ ALPHABAT_DOUBLE: RegExp;
93
+ /**
94
+ * //中文
95
+ */
96
+ CHINESE: RegExp;
97
+ /**
98
+ * //中文大小写字母和数字
99
+ */
100
+ CHINESE_ALPHA_NUMERIC: RegExp;
101
+ /**
102
+ * //日期 YYYY-MM-DD
103
+ */
104
+ DATE: RegExp;
105
+ /**
106
+ * //时间 HH:mm:ss
107
+ */
108
+ TIME: RegExp;
109
+ /**
110
+ * //日期时间 YYYY-MM-DD HH:mm:ss
111
+ */
112
+ DATE_TIME: RegExp;
113
+ /**
114
+ * //日期时间匹配
115
+ */
116
+ DATE_TIME_MATCH: RegExp;
117
+ /**
118
+ * //HTML标签
119
+ */
120
+ HTML: RegExp;
121
+ /**
122
+ * //HTML标签匹配
123
+ */
124
+ HTML_TAG: RegExp;
125
+ /**
126
+ * //HTML标签名称匹配
127
+ */
128
+ HTML_TAG_NAME: RegExp;
129
+ /**
130
+ * //手机号 支持 11位 + 国别
131
+ */
132
+ MOBILE: RegExp;
133
+ /**
134
+ * //手机号11位
135
+ */
136
+ MOBILE_11: RegExp;
137
+ /**
138
+ * //IP地址
139
+ */
140
+ IP: RegExp;
141
+ /**
142
+ * //MAC地址
143
+ */
144
+ MAC: RegExp;
145
+ /**
146
+ * //QQ号
147
+ */
148
+ QQ: RegExp;
149
+ /**
150
+ * //邮政编码
151
+ */
152
+ POSTAL_CODE: RegExp;
153
+ /**
154
+ * //邮箱
155
+ */
156
+ EMAIL: RegExp;
157
+ /**
158
+ * //身份证
159
+ */
160
+ IDCARD: RegExp;
161
+ IPv6: RegExp;
162
+ };
163
+ export default _Regexps_;
164
+ export declare type Regexps = typeof _Regexps_;
@@ -0,0 +1,42 @@
1
+ import { AxiosRequestConfig } from '/#/types/axios';
2
+ export type RequestConfig = {
3
+ meta?: {
4
+ /**
5
+ * 是否忽略节流,默认false
6
+ */
7
+ ignoreThrottle?: boolean;
8
+ /**
9
+ * 节流时长,单位毫秒
10
+ */
11
+ throttleDuration?: number;
12
+ } & Record<any, any>;
13
+ } & AxiosRequestConfig;
14
+ declare const Requests: {
15
+ /**
16
+ * 节流请求
17
+ * 在指定的节流时长内,相同的请求会被合并,只执行一次实际请求
18
+ * 多个调用者会共享同一个响应结果
19
+ *
20
+ * @param config 请求参数
21
+ * @param request 实际请求函数
22
+ * @param duration 节流时长 单位/毫秒 默认=1000
23
+ * @returns Promise<响应结果>
24
+ *
25
+ * @example
26
+ * // 基本使用
27
+ * const result = await Requests.ThrottleRequest(
28
+ * { url: '/api/data', method: 'GET' },
29
+ * axios.request,
30
+ * 1000 // 1秒内相同请求只发一次
31
+ * );
32
+ *
33
+ * @example
34
+ * // 忽略节流
35
+ * const result = await Requests.ThrottleRequest(
36
+ * { url: '/api/data', meta: { ignoreThrottle: true } },
37
+ * axios.request
38
+ * );
39
+ */
40
+ ThrottleRequest<P extends RequestConfig, R = any>(config: P, request: (config: P) => Promise<R>, duration?: number): Promise<R>;
41
+ };
42
+ export default Requests;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * 输入类型:string | Uint8Array | Int8Array | number[]
3
+ */
4
+ type SHAInput = string | Uint8Array | Int8Array | number[];
5
+ /**
6
+ * 进度信息
7
+ */
8
+ export interface ProgressInfo {
9
+ /** 已读取字节数 */
10
+ loaded: number;
11
+ /** 文件总字节数 */
12
+ total: number;
13
+ /** 进度百分比 (0-100) */
14
+ percent: number;
15
+ }
16
+ /**
17
+ * 文件哈希计算选项
18
+ */
19
+ export interface FileHashOptions {
20
+ /** 分块大小,默认 4MB */
21
+ chunkSize?: number;
22
+ /** 进度回调函数 */
23
+ onProgress?: (info: ProgressInfo) => void;
24
+ }
25
+ /**
26
+ * 文件输入类型:浏览器 File 对象或 Node.js 文件路径字符串
27
+ */
28
+ type FileInput = File | string;
29
+ declare const SHA: {
30
+ /**
31
+ * SHA1 加密
32
+ * @param src 输入数据
33
+ * @returns hex 字符串(40 字符)
34
+ */
35
+ sha1(src: SHAInput): string | null;
36
+ /**
37
+ * SHA224 加密
38
+ * @param data 输入数据
39
+ * @returns hex 字符串(56 字符)
40
+ */
41
+ sha224(data: SHAInput): string | null;
42
+ /**
43
+ * SHA256 加密
44
+ * @param src 输入数据
45
+ * @returns hex 字符串(64 字符)
46
+ */
47
+ sha256(src: SHAInput): string | null;
48
+ /**
49
+ * SHA384 加密
50
+ * @param src 输入数据
51
+ * @returns hex 字符串(96 字符)
52
+ */
53
+ sha384(src: SHAInput): string | null;
54
+ /**
55
+ * SHA512 加密
56
+ * @param src 输入数据
57
+ * @returns hex 字符串(128 字符)
58
+ */
59
+ sha512(src: SHAInput): string | null;
60
+ /**
61
+ * 计算 SHA256 文件哈希(支持大文件流式计算)
62
+ * @param file 文件对象(浏览器)或文件路径(Node.js)
63
+ * @param options 可选配置:分块大小、进度回调
64
+ * @returns Promise<string> 返回哈希值(64 字符 hex)
65
+ * @example
66
+ * // Node.js
67
+ * const hash = await SHA.sha256File('/path/to/file.mp4', {
68
+ * onProgress: (p) => console.log(`${p.percent}%`)
69
+ * });
70
+ * // 浏览器
71
+ * const hash = await SHA.sha256File(fileInput.files[0]);
72
+ */
73
+ sha256File(file: FileInput, options?: FileHashOptions): Promise<string>;
74
+ /**
75
+ * 计算 SHA512 文件哈希(支持大文件流式计算)
76
+ * @param file 文件对象(浏览器)或文件路径(Node.js)
77
+ * @param options 可选配置:分块大小、进度回调
78
+ * @returns Promise<string> 返回哈希值(128 字符 hex)
79
+ * @example
80
+ * // Node.js
81
+ * const hash = await SHA.sha512File('/path/to/large-file.zip');
82
+ * // 浏览器
83
+ * const hash = await SHA.sha512File(fileInput.files[0], {
84
+ * chunkSize: 8 * 1024 * 1024, // 8MB 分块
85
+ * onProgress: (p) => updateProgressBar(p.percent)
86
+ * });
87
+ */
88
+ sha512File(file: FileInput, options?: FileHashOptions): Promise<string>;
89
+ };
90
+ export default SHA;
91
+ export type SHA = typeof SHA;
@@ -0,0 +1,90 @@
1
+ export type TreeNodeEF = {
2
+ __level__: number;
3
+ __isRoot__: boolean;
4
+ } & Record<any, any>;
5
+ /**
6
+ * @param curr 当前项
7
+ * @param parent 父项
8
+ * @param idx 当前项目所在列表中的索引
9
+ * @param arr 当前项所在的列表对象
10
+ */
11
+ export type EachTreeConsumer<T> = {
12
+ /**
13
+ *
14
+ * @param curr 当前节点
15
+ * @param parent 父节点
16
+ * @param idx 当前节点所在列表的索引
17
+ * @param arr 当前节点所在的列表
18
+ */
19
+ (curr: T, parent?: T | null, idx?: number, arr?: T[]): any;
20
+ };
21
+ /**
22
+ * 筛选器
23
+ * @param c 当前节点
24
+ * @param p 父节点
25
+ * @param idx 当前节点在列表中的索引
26
+ * @param arr 当前节点所在的列表
27
+ */
28
+ export type TreeFilter<T> = {
29
+ /**
30
+ *
31
+ * @param c 当前节点
32
+ * @param p 父节点
33
+ * @param idx 当前节点在列表中的索引
34
+ * @param arr 当前节点所在的列表
35
+ * */
36
+ (c: T, p: T | null, idx: number, arr?: T[]): boolean;
37
+ };
38
+ declare const _TreeUtils_: {
39
+ /**
40
+ * 构建树型结构
41
+ * @param arr 数据列表
42
+ * @param idField id 唯一标识节点名称.默认=id
43
+ * @param parentField 父级节点名称.默认=parentId
44
+ * @param childrenField 子节点名称 .默认=children
45
+ */
46
+ buildTree<T, C extends string, R = T & {
47
+ __level__: number;
48
+ __isRoot__: boolean;
49
+ } & Record<any, any> & { [K in C]: R[]; }>(arr: T[], idField?: string, parentField?: string, childrenField?: C | "children"): R[];
50
+ /**
51
+ * 遍历树节点
52
+ * @param arr
53
+ * @param callback
54
+ * @param childrenField 默认=children
55
+ */
56
+ eachTree<T, R = T>(arr: T[], callback: EachTreeConsumer<T>, childrenField?: string | "children"): R[];
57
+ /**
58
+ * 查找 树节点 只返回一项
59
+ * @param treeList
60
+ * @param filter
61
+ * @param childrenField 默认=children
62
+ */
63
+ findTreeItem<T>(treeList: T[], filter: TreeFilter<T>, childrenField?: string | "children"): T | null;
64
+ /**
65
+ * 输转 数组
66
+ * @param arr
67
+ * @param childrenField 默认=children
68
+ * @param removeChildren 是否删除 children 节点
69
+ */
70
+ treeToArray<T>(arr: T[] | T, childrenField?: string, removeChildren?: boolean): T[];
71
+ /**
72
+ * 查找 一项
73
+ * @param arr 数据源
74
+ * @param filter 筛选器
75
+ * @param childrenField 默认=children
76
+ *
77
+ * @return The first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
78
+ */
79
+ find<T>(arr: T[], filter: TreeFilter<T>, childrenField?: string | "children"): T | null;
80
+ /**
81
+ * 查找数
82
+ * @param arr 数列表
83
+ * @param filter 过滤器
84
+ * @param childrenField 默认=children
85
+ * @return A shallow copy of the given array containing just the elements that pass the test. If no elements pass the test, an empty array is returned.
86
+ */
87
+ filter<T>(arr: T[], filter: TreeFilter<T>, childrenField?: string | "children"): T[];
88
+ };
89
+ export default _TreeUtils_;
90
+ export declare type TreeUtils = typeof _TreeUtils_;