gzjs-utils 1.0.20 → 1.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gzjs-utils",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "smart js utils",
5
5
  "main": "lib/index.js",
6
6
  "typings": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -1,31 +1,2 @@
1
- import { Utils } from "./utils/Utils";
2
- import { WebRTCIP } from "./utils/WebRTCIP";
3
- import { Bytes } from "./utils/Bytes";
4
- import { Base64 } from "./utils/Base64";
5
- import { MD5 } from "./utils/MD5";
6
- import { Env } from "./utils/Env";
7
- import EnumBuilder from "./utils/EnumBuilder";
8
- import { AES } from "./utils/AES";
9
- import _Hmac_ from "./utils/Hmac";
10
- import _SHA_ from "./utils/SHA";
11
- import { KeyTool } from "./utils/types/KeyTool";
12
- export type GzjsUtils = Utils & WebRTCIP & {
13
- Bytes: Bytes;
14
- Base64: Base64;
15
- Utils: Utils;
16
- MD5: MD5;
17
- AES: AES;
18
- Hmac: typeof _Hmac_;
19
- SHA: typeof _SHA_;
20
- EnumBuilder: typeof EnumBuilder;
21
- KeyTool: KeyTool;
22
- getEnvironments(): Env;
23
- version: string;
24
- /**
25
- * 关闭工具日志警告
26
- * @param flag
27
- */
28
- disable_warning?: (flag?: boolean) => void;
29
- };
30
- declare const JsUtils: GzjsUtils;
31
- export default JsUtils;
1
+ import _JsUtils_ from "./utils";
2
+ export default _JsUtils_;
@@ -1,4 +1,22 @@
1
- import { Options } from "./types/AesType";
1
+ export type IV = number[] | string | Uint8Array | Int8Array;
2
+ export type Options = {
3
+ /**
4
+ * 填充方式 pck7padding
5
+ */
6
+ padding?: string | "PKCS#5" | "PKCS#7" | "NoPadding" | "PKCS5Padding" | "PKCS7Padding" | "pkcs5padding" | "pkcs7padding";
7
+ /**
8
+ * 16 bytes iv
9
+ */
10
+ iv?: IV;
11
+ /**
12
+ * 分段大小
13
+ */
14
+ segmentSize?: number;
15
+ /**
16
+ * CTR 模式参数 向量初始值
17
+ */
18
+ count?: IV | number;
19
+ };
2
20
  declare const provders: {
3
21
  ECB: {
4
22
  /**
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 日期工具类
3
+ */
4
+ export type DateUtils = {
5
+ /**
6
+ * 指定日期获取值,返回格式 yyyy-MM-dd hh:mm:ss
7
+ * @param date 指定时间, 默认=当前时间
8
+ */
9
+ getDateTime(date?: Date): string;
10
+ /**
11
+ * 指定日期获取值, 返回格式 yyyy-MM-dd
12
+ * @param date 指定时间, 默认=当前时间
13
+ */
14
+ getDateString(date?: Date): string;
15
+ /**
16
+ * 指定日期获取值,返回格式 yyyyMMdd
17
+ * @param date 指定时间, 默认=当前时间
18
+ */
19
+ getDateInt(date?: Date): string;
20
+ /**
21
+ * 日期格式化<br>
22
+ *
23
+ * <pre>
24
+ * fmt 参数 接受内容如下:
25
+ * Y|y = 年, 范围:yy | yyyy | YY |YYYY。yy|YY = 表示2025 中的25
26
+ * M = 月, 范围:M: 1-12,MM: 01-12
27
+ * d = 日, 范围:d: 1-31,dd: 01-31
28
+ * H = 时, 范围:H: 0-23,HH: 00-23
29
+ * H = 时, 范围:h: 0-12,hh: 00-12
30
+ * m = 分, 范围:h: 0-59,mm: 00-59
31
+ * s = 秒, 范围:s: 0-59,ss: 00-59
32
+ * f|F|S = 毫秒,范围:s: 0-9,ff: 00-99,fff:000-999
33
+ * A = AM | PM
34
+ * a = am | pm
35
+ * w = 一周中的一天,范围:w: 0-6,ww:00-06
36
+ * W = 星期几,Sunday - Saturday
37
+ * </pre>
38
+ *
39
+ * @param date
40
+ * @param fmt 格式内容
41
+ */
42
+ format(date: Date, fmt: string): string;
43
+ };
44
+ declare const _DateUtils_: DateUtils;
45
+ export default _DateUtils_;
@@ -1,4 +1,4 @@
1
- import { EnumItem } from "./types/Global";
1
+ import { EnumItem } from "./index";
2
2
  type SimpleType = string | number | undefined | null;
3
3
  interface ET extends EnumItem {
4
4
  }
@@ -1,2 +1,2 @@
1
- export type Env = NodeJS.ProcessEnv;
1
+ export type Env = typeof process.env;
2
2
  export declare const getEnvironments: () => Env;
@@ -0,0 +1,87 @@
1
+ export type TreeNodeEF = {
2
+ __level__: number;
3
+ __isRoot__: boolean;
4
+ };
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, R = T & TreeNodeEF>(arr: T[], idField?: string | "id", parentField?: string | "parentId", childrenField?: string | "children"): R[];
47
+ /**
48
+ * 遍历树节点
49
+ * @param arr
50
+ * @param callback
51
+ * @param childrenField 默认=children
52
+ */
53
+ eachTree<T, R = T>(arr: T[], callback: EachTreeConsumer<T>, childrenField?: string | "children"): R[];
54
+ /**
55
+ * 查找 树节点 只返回一项
56
+ * @param treeList
57
+ * @param filter
58
+ * @param childrenField 默认=children
59
+ */
60
+ findTreeItem<T>(treeList: T[], filter: TreeFilter<T>, childrenField?: string | "children"): T | null;
61
+ /**
62
+ * 输转 数组
63
+ * @param arr
64
+ * @param childrenField 默认=children
65
+ * @param removeChildren 是否删除 children 节点
66
+ */
67
+ treeToArray<T>(arr: T[] | T, childrenField?: string, removeChildren?: boolean): T[];
68
+ /**
69
+ * 查找 一项
70
+ * @param arr 数据源
71
+ * @param filter 筛选器
72
+ * @param childrenField 默认=children
73
+ *
74
+ * @return The first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
75
+ */
76
+ find<T>(arr: T[], filter: TreeFilter<T>, childrenField?: string | "children"): T | null;
77
+ /**
78
+ * 查找数
79
+ * @param arr 数列表
80
+ * @param filter 过滤器
81
+ * @param childrenField 默认=children
82
+ * @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.
83
+ */
84
+ filter<T>(arr: T[], filter: TreeFilter<T>, childrenField?: string | "children"): T[];
85
+ };
86
+ export default _TreeUtils_;
87
+ export type TreeUtils = typeof _TreeUtils_;
@@ -17,19 +17,6 @@ declare type day = number;
17
17
  * 2=trim右边空白
18
18
  */
19
19
  declare type TrimMode = 0 | 1 | 2;
20
- export type TreeNodeEF = {
21
- __level__: number;
22
- __isRoot__: boolean;
23
- };
24
- /**
25
- * @param curr 当前项
26
- * @param parent 父项
27
- * @param idx 当前项目所在列表中的索引
28
- * @param arr 当前项所在的列表对象
29
- */
30
- export type EachTreeProcesstor<T> = {
31
- (curr: T, parent: T | null, idx: number, arr: T[]): any;
32
- };
33
20
  export type URI = {
34
21
  "source": string | "";
35
22
  "protocol": string | "";
@@ -44,11 +31,13 @@ export type URI = {
44
31
  "directory": string | "";
45
32
  "file": string | "";
46
33
  "query": string | "";
47
- anchor: string | "";
34
+ "anchor": string | "";
48
35
  "origin": string | "";
49
- params: {
36
+ "hash": string | "";
37
+ "params": {
50
38
  [key: string]: string | boolean | any[] | "";
51
39
  };
40
+ toURLString: () => string;
52
41
  };
53
42
  export type RandomTypeOrSource = 1 | 2 | 3 | (number | string)[] | string;
54
43
  export declare type Utils = {
@@ -157,7 +146,31 @@ export declare type Utils = {
157
146
  * @param search 查询参数,如果为空则会 从url 读取
158
147
  * @param allowFromLocation 允许从 location 上获取
159
148
  */
160
- getQueryParams(search?: string, allowFromLocation?: boolean): Record<any, string | number | boolean | null> | object;
149
+ getQueryParams(search?: string, allowFromLocation?: boolean): Record<any, any> | object;
150
+ /**
151
+ * 新增参数到URL上
152
+ * @param url url
153
+ * @param key 参数名
154
+ * @param value 参数值
155
+ * @param override 是否覆盖原有参数,默认=false
156
+ * @return new url
157
+ */
158
+ addParamToURL(url: string, key: string, value: any, override?: boolean): string;
159
+ /**
160
+ * 新增参数到URL上
161
+ * @param url url
162
+ * @param params 参数对象
163
+ * @param override 是否覆盖原有参数,默认=false
164
+ * @return new url
165
+ */
166
+ addParamObjToURL(url: string, params: Record<any, any> | object, override?: boolean): string;
167
+ /**
168
+ * 删除参数到URL上
169
+ * @param url url
170
+ * @param keys 参数
171
+ * @return new url
172
+ **/
173
+ removeParamFromURL(url: string, keys?: string[] | string): string;
161
174
  /**
162
175
  * 字符串是否全部是中文
163
176
  * @param obj
@@ -234,35 +247,6 @@ export declare type Utils = {
234
247
  * @param v6
235
248
  */
236
249
  isIP(str: any_str, v6?: boolean): boolean;
237
- /**
238
- * 构建树型结构
239
- * @param arr 数据列表
240
- * @param idField id 唯一标识节点名称
241
- * @param parentField 父级节点名称
242
- * @param childrenField 子节点名称
243
- */
244
- buildTree<T, R = T & TreeNodeEF>(arr: T[], idField?: "id", parentField?: "parentId", childrenField?: "children"): R[];
245
- /**
246
- * 遍历树节点
247
- * @param arr
248
- * @param processter
249
- * @param childrenKey
250
- */
251
- eachTree<T, R = T>(arr: T[], processter: EachTreeProcesstor<T>, childrenKey?: string | 'children'): R[];
252
- /**
253
- * 输转 数组
254
- * @param arr
255
- * @param childrenKey
256
- * @param removeChildren 是否删除 children 节点
257
- */
258
- treeToArray<T>(arr: T[] | T, childrenKey?: string, removeChildren?: boolean): T[];
259
- /**
260
- * 查找 树节点 只返回一项
261
- * @param treeList
262
- * @param filter
263
- * @param childrenKey
264
- */
265
- findTreeItem<T>(treeList: T[], filter: (c: T, p: T | null) => boolean, childrenKey?: string | ((c: T) => T[])): T | null;
266
250
  getDPI(): number;
267
251
  /**
268
252
  * 毫米转像素
@@ -0,0 +1,123 @@
1
+ import { Utils } from "./Utils";
2
+ import { WebRTCIP } from "./WebRTCIP";
3
+ import { Bytes } from "./Bytes";
4
+ import { Base64 } from "./Base64";
5
+ import { MD5 } from "./MD5";
6
+ import { AES } from "./AES";
7
+ import _Hmac_ from "./Hmac";
8
+ import _SHA_ from "./SHA";
9
+ import EnumBuilder from "./EnumBuilder";
10
+ import { Env } from "./Env";
11
+ import { TreeUtils } from "./TreeUtils";
12
+ import { DateUtils } from "./DateUtils";
13
+ export type KeyInfo = {
14
+ /**
15
+ * 请求过期时长,单位/秒
16
+ */
17
+ req: number;
18
+ /**
19
+ * 申请日期, yyyy-MM-dd HH:mm:ss
20
+ */
21
+ begin: string;
22
+ /**
23
+ * 到期时间,yyyy-MM-dd HH:mm:ss
24
+ */
25
+ end: string;
26
+ /**
27
+ * 是否可用
28
+ */
29
+ enabled: boolean;
30
+ /**
31
+ * 相对有效 日期 的可用时长,如果 enabled=false,则表示 已过期的时长
32
+ */
33
+ diff: number;
34
+ /**
35
+ * 扩展数据
36
+ */
37
+ data?: string;
38
+ };
39
+ /**
40
+ * 枚举项
41
+ */
42
+ export interface EnumItem {
43
+ /**
44
+ * 枚举项名称
45
+ */
46
+ label: string;
47
+ /**
48
+ * 枚举项描述
49
+ */
50
+ desc?: string;
51
+ /**
52
+ * 枚举项编码,默认枚举值
53
+ */
54
+ value: string | number;
55
+ /**
56
+ * 扩展值
57
+ */
58
+ values?: (string | number)[];
59
+ /**
60
+ * 比较是否相等,
61
+ * @param val
62
+ */
63
+ eq?: (val: any | string) => boolean;
64
+ /**
65
+ * 文字颜色值
66
+ */
67
+ color?: string;
68
+ /**
69
+ * 背景颜色
70
+ */
71
+ bgColor?: string;
72
+ }
73
+ export type KeyTool = {
74
+ version: string;
75
+ /**
76
+ * 读取授权码信息
77
+ * @param key
78
+ */
79
+ readKey(key: string): KeyInfo;
80
+ /**
81
+ * 创建授权码
82
+ * @param seconds 授权码授权时长,单位/秒
83
+ * @param ext_data 扩展数据
84
+ */
85
+ createKey(seconds?: number, ext_data?: any): string;
86
+ };
87
+ /**
88
+ * 分页参数
89
+ */
90
+ export type PageParam = {
91
+ pageNo?: number | 1;
92
+ pageSize?: number | 10;
93
+ };
94
+ /**
95
+ * 分页结果对象
96
+ */
97
+ export type PageResult<T = any> = {
98
+ list: T[];
99
+ total: number;
100
+ };
101
+ type TreeUtilBase = Pick<TreeUtils, 'buildTree' | 'eachTree' | 'findTreeItem' | 'treeToArray'>;
102
+ export type JsUtils = Utils & TreeUtilBase & WebRTCIP & {
103
+ Bytes: Bytes;
104
+ Base64: Base64;
105
+ Utils: Utils;
106
+ DateUtils: DateUtils;
107
+ TreeUtils: TreeUtils;
108
+ MD5: MD5;
109
+ AES: AES;
110
+ Hmac: typeof _Hmac_;
111
+ SHA: typeof _SHA_;
112
+ EnumBuilder: typeof EnumBuilder;
113
+ readonly KeyTool: KeyTool;
114
+ getEnvironments(): Env;
115
+ readonly version: string;
116
+ /**
117
+ * 关闭工具日志警告
118
+ * @param flag
119
+ */
120
+ disable_warning?: (flag?: boolean) => void;
121
+ };
122
+ declare const _JsUtils_: JsUtils;
123
+ export default _JsUtils_;
@@ -1,86 +0,0 @@
1
- export declare class RTCHttpHeader {
2
- private store;
3
- getHeader(name: string): any;
4
- addHeader(name: string, value: string | number): void;
5
- getHeaderNames(): string[];
6
- removeHeader(name: string): void;
7
- values(): string[];
8
- has(name: string): boolean;
9
- entries(): [string, any][];
10
- }
11
- export declare class HttpResult {
12
- private headers;
13
- private responseData;
14
- private statusCode;
15
- private statusMsg;
16
- constructor(props: {
17
- headers: Record<string, string>;
18
- statusCode: number;
19
- statusMsg: string;
20
- responseData: Int8Array | null;
21
- config: any;
22
- });
23
- /**
24
- * 获取HTTP响应头
25
- */
26
- getHeaders(): Record<any, string>;
27
- /**
28
- * 指定获取响应头
29
- * @param name
30
- */
31
- getHeader(name: string): string;
32
- /**
33
- * 获取响应状态码
34
- */
35
- getStatusCode(): number;
36
- /**
37
- * 获取状态码消息
38
- */
39
- getStatusMsg(): string;
40
- /**
41
- * 获取获取响应文本
42
- */
43
- getResponseText(): string | null;
44
- /**
45
- * 获取响应数据流
46
- */
47
- getResponseData(): Int8Array | null;
48
- }
49
- export type HttpRequestConfig = {};
50
- export declare class RTCHttpClient {
51
- private readonly id;
52
- constructor(props: HttpRequestConfig);
53
- getId(): string;
54
- /**
55
- * post 请求
56
- * @param url
57
- * @param data 请求数据
58
- * @param params url 参数
59
- * @param headers 自定义请求头
60
- */
61
- post(url: string, data?: any, params?: Record<any, any>, headers?: Record<any, string>): Promise<HttpResult>;
62
- /**
63
- * get 请求
64
- * @param url
65
- * @param params
66
- * @param headers
67
- */
68
- get(url: string, params?: Record<any, any>, headers?: Record<any, string>): Promise<HttpResult>;
69
- request(params: {
70
- url: string;
71
- method?: string | "GET";
72
- params?: Record<string, any>;
73
- data?: any;
74
- headers?: Record<string, string>;
75
- }): Promise<HttpResult>;
76
- }
77
- export declare const instance: (config: HttpRequestConfig) => RTCHttpClient;
78
- export declare function request(params: {
79
- url: string;
80
- method?: string | "GET";
81
- params?: Record<string, any>;
82
- data?: any;
83
- headers?: Record<string, string>;
84
- }, config?: HttpRequestConfig): Promise<HttpResult>;
85
- declare const defaults: RTCHttpClient;
86
- export default defaults;
@@ -1,19 +0,0 @@
1
- export type IV = number[] | string | Uint8Array | Int8Array;
2
- export type Options = {
3
- /**
4
- * 填充方式 pck7padding
5
- */
6
- padding?: string | "PKCS#5" | "PKCS#7" | "NoPadding" | "PKCS5Padding" | "PKCS7Padding" | "pkcs5padding" | "pkcs7padding";
7
- /**
8
- * 16 bytes iv
9
- */
10
- iv?: IV;
11
- /**
12
- * 分段大小
13
- */
14
- segmentSize?: number;
15
- /**
16
- * CTR 模式参数 向量初始值
17
- */
18
- count?: IV | number;
19
- };
@@ -1,64 +0,0 @@
1
- export type PageParam = {
2
- pageNo: number | 1;
3
- pageSize: number | 10;
4
- };
5
- export type KeyInfo = {
6
- /**
7
- * 请求过期时长,单位/秒
8
- */
9
- req: number;
10
- /**
11
- * 申请日期, yyyy-MM-dd HH:mm:ss
12
- */
13
- begin: string;
14
- /**
15
- * 到期时间,yyyy-MM-dd HH:mm:ss
16
- */
17
- end: string;
18
- /**
19
- * 是否可用
20
- */
21
- enabled: boolean;
22
- /**
23
- * 相对有效 日期 的可用时长,如果 enabled=false,则表示 已过期的时长
24
- */
25
- diff: number;
26
- /**
27
- * 扩展数据
28
- */
29
- data?: string;
30
- };
31
- /**
32
- * 枚举项
33
- */
34
- export interface EnumItem {
35
- /**
36
- * 枚举项名称
37
- */
38
- label: string;
39
- /**
40
- * 枚举项描述
41
- */
42
- desc?: string;
43
- /**
44
- * 枚举项编码,默认枚举值
45
- */
46
- value: string | number;
47
- /**
48
- * 扩展值
49
- */
50
- values?: (string | number)[];
51
- /**
52
- * 比较是否相等,
53
- * @param val
54
- */
55
- eq?: (val: any | string) => boolean;
56
- /**
57
- * 文字颜色值
58
- */
59
- color?: string;
60
- /**
61
- * 背景颜色
62
- */
63
- bgColor?: string;
64
- }
@@ -1,15 +0,0 @@
1
- import { KeyInfo } from "./Global";
2
- export type KeyTool = {
3
- version: string;
4
- /**
5
- * 读取授权码信息
6
- * @param key
7
- */
8
- readKey(key: string): KeyInfo;
9
- /**
10
- * 创建授权码
11
- * @param seconds 授权码授权时长,单位/秒
12
- * @param ext_data 扩展数据
13
- */
14
- createKey(seconds?: number, ext_data?: any): string;
15
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * 分页结果对象
3
- */
4
- export type PageResult<T = any> = {
5
- list: T[];
6
- total: number;
7
- };