gzjs-utils 1.0.25 → 1.0.26
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/lib/index.cjs +1 -0
- package/lib/index.iife.js +1 -0
- package/lib/index.mjs +1 -0
- package/lib/index.umd.js +1 -0
- package/package.json +38 -7
- package/types/index.d.ts +12 -2
- package/types/utils/AES.d.ts +53 -64
- package/types/utils/Base64.d.ts +25 -25
- package/types/utils/Bytes.d.ts +40 -40
- package/types/utils/Console.d.ts +45 -0
- package/types/utils/DateUtils.d.ts +14 -18
- package/types/utils/EnumBuilder.d.ts +1 -1
- package/types/utils/Env.d.ts +2 -1
- package/types/utils/ExpUtils.d.ts +74 -0
- package/types/utils/Hmac.d.ts +70 -23
- package/types/utils/MD5.d.ts +57 -7
- package/types/utils/Promise.d.ts +16 -9
- package/types/utils/Regexps.d.ts +164 -0
- package/types/utils/Requests.d.ts +42 -0
- package/types/utils/SHA.d.ts +80 -18
- package/types/utils/TreeUtils.d.ts +1 -1
- package/types/utils/Utils.d.ts +334 -166
- package/types/utils/index.d.ts +42 -18
- package/LICENSE +0 -21
- package/lib/index.js +0 -1
package/package.json
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gzjs-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "smart js utils",
|
|
5
|
-
"main": "lib/index.
|
|
5
|
+
"main": "lib/index.cjs",
|
|
6
|
+
"module": "lib/index.mjs",
|
|
7
|
+
"browser": "lib/index.umd.js",
|
|
6
8
|
"typings": "types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./lib/index.mjs",
|
|
12
|
+
"require": "./lib/index.cjs",
|
|
13
|
+
"browser": "./lib/index.umd.js",
|
|
14
|
+
"types": "./types/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
7
17
|
"scripts": {
|
|
8
|
-
"dev": "
|
|
9
|
-
"build": "
|
|
10
|
-
"
|
|
18
|
+
"dev": "vite",
|
|
19
|
+
"build": "vite build",
|
|
20
|
+
"preview": "vite preview",
|
|
21
|
+
"test": "tsx test/test-crypto.ts && tsx test/test-file-hash.ts && tsx test/test-clone.ts && tsx test/test-promise.ts && tsx test/test-throttle.ts",
|
|
22
|
+
"test:crypto": "tsx test/test-crypto.ts",
|
|
23
|
+
"test:file": "tsx test/test-file-hash.ts",
|
|
24
|
+
"test:clone": "tsx test/test-clone.ts",
|
|
25
|
+
"test:promise": "tsx test/test-promise.ts",
|
|
26
|
+
"test:throttle": "tsx test/test-throttle.ts"
|
|
11
27
|
},
|
|
12
28
|
"repository": {
|
|
13
29
|
"type": "git",
|
|
@@ -19,9 +35,24 @@
|
|
|
19
35
|
"AES",
|
|
20
36
|
"Base64",
|
|
21
37
|
"MD5",
|
|
22
|
-
"
|
|
38
|
+
"SHA",
|
|
39
|
+
"SHA1",
|
|
40
|
+
"SHA224",
|
|
41
|
+
"SHA256",
|
|
42
|
+
"SHA384",
|
|
43
|
+
"SHA512",
|
|
44
|
+
"Hmac",
|
|
23
45
|
"Bytes"
|
|
24
46
|
],
|
|
25
47
|
"author": "xiyuan-lgz",
|
|
26
|
-
"license": "ISC"
|
|
48
|
+
"license": "ISC",
|
|
49
|
+
"files": [
|
|
50
|
+
"lib",
|
|
51
|
+
"types",
|
|
52
|
+
"LICENSE"
|
|
53
|
+
],
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"crypto-js": "^4.2.0",
|
|
56
|
+
"eval5": "^1.4.8"
|
|
57
|
+
}
|
|
27
58
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { default as JsUtils } from './utils';
|
|
2
|
+
import { default as AES } from './utils/AES';
|
|
3
|
+
import { default as Base64 } from './utils/Base64';
|
|
4
|
+
import { default as MD5 } from './utils/MD5';
|
|
5
|
+
import { default as Hmac } from './utils/Hmac';
|
|
6
|
+
import { default as SHA } from './utils/SHA';
|
|
7
|
+
import { default as Bytes } from './utils/Bytes';
|
|
8
|
+
import { default as TreeUtils } from './utils/TreeUtils';
|
|
9
|
+
import { default as Regexps } from './utils/Regexps';
|
|
10
|
+
import { default as DateUtils } from './utils/DateUtils';
|
|
11
|
+
export default JsUtils;
|
|
12
|
+
export { AES, JsUtils, Base64, Bytes, MD5, Hmac, SHA, TreeUtils, Regexps, DateUtils };
|
package/types/utils/AES.d.ts
CHANGED
|
@@ -26,76 +26,43 @@ declare const provders: {
|
|
|
26
26
|
* @param opts
|
|
27
27
|
*/
|
|
28
28
|
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding">): Uint8Array;
|
|
29
|
-
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding">): Uint8Array
|
|
29
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding">): Uint8Array<ArrayBufferLike>;
|
|
30
30
|
encode(key: string, plaintext: string, opts?: Pick<Options, "padding">): string;
|
|
31
31
|
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding">): string;
|
|
32
32
|
};
|
|
33
33
|
CBC: {
|
|
34
34
|
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array;
|
|
35
|
-
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array
|
|
35
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array<ArrayBufferLike>;
|
|
36
36
|
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
37
37
|
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
38
38
|
};
|
|
39
39
|
CFB: {
|
|
40
40
|
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): Uint8Array;
|
|
41
|
-
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): Uint8Array
|
|
41
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): Uint8Array<ArrayBufferLike>;
|
|
42
42
|
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): string;
|
|
43
43
|
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): string;
|
|
44
44
|
};
|
|
45
45
|
OFB: {
|
|
46
46
|
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array;
|
|
47
|
-
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array
|
|
47
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array<ArrayBufferLike>;
|
|
48
48
|
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
49
49
|
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
50
50
|
};
|
|
51
51
|
CTR: {
|
|
52
52
|
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array;
|
|
53
|
-
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array
|
|
53
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array<ArrayBufferLike>;
|
|
54
54
|
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
55
55
|
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
56
56
|
};
|
|
57
57
|
};
|
|
58
58
|
export type Mode = keyof typeof provders | string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* <li>Pure JavaScript (with no dependencies)</li>
|
|
67
|
-
* <li>Supports all key sizes (128-bit, 192-bit and 256-bit)</li>
|
|
68
|
-
* <li>Supports all common modes of operation (CBC, CFB, CTR, ECB and OFB)</li>
|
|
69
|
-
* <li>Works in either node.js or web browsers</li>
|
|
70
|
-
* </ul>
|
|
71
|
-
*
|
|
72
|
-
* <h1>API</h1>
|
|
73
|
-
* <strong>Node.js</strong>
|
|
74
|
-
* <span>To install <code>gzjs-utils</code> in your node.js project:</span>
|
|
75
|
-
* <pre>npm install gzjs-utils</pre>
|
|
76
|
-
*
|
|
77
|
-
* 通用用法 为 <code>浏览器引入js 后 会注册全局变量JsUtils</code>
|
|
78
|
-
* <pre>
|
|
79
|
-
* const JsUtils = require('gzjs-utils');
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* const iv = "<IV>" // iv must 16 bytes
|
|
83
|
-
* const key = "<aesKey>"; // keys must be 128 bits (16 bytes), 192 bits (24 bytes) or 256 bits (32 bytes)
|
|
84
|
-
* const mode = '<mode>' // ECB,CBC, CFB,OFB,CTR
|
|
85
|
-
* const padding = "PKCS#7" // 填充方式, PKCS#7 | PKCS#5 | NoPadding
|
|
86
|
-
* const plaintext = '<plaintext>';
|
|
87
|
-
* const ciphertext = '<plaintext>';
|
|
88
|
-
*
|
|
89
|
-
* JsUtils.AES.encode(key, <plaintext>, {mode: <mode>, iv: <iv>, padding: <padding>}); // return hex string
|
|
90
|
-
* JsUtils.AES.encrypt(key, <plaintext>, {mode: <mode>, iv: <iv>, padding: <padding>}); // return Uint8Array
|
|
91
|
-
*
|
|
92
|
-
* JsUtils.AES.decode(key, <ciphertext>, {mode: <mode>, iv: <iv>, padding: <padding>}); // return plaintext
|
|
93
|
-
* JsUtils.AES.decrypt(key, <ciphertext>, {mode: <mode>, iv: <iv>, padding: <padding>}); // return plaintext as Uint8Array
|
|
94
|
-
*
|
|
95
|
-
* </pre>
|
|
96
|
-
*
|
|
97
|
-
*/
|
|
98
|
-
export type AES = typeof provders & {
|
|
59
|
+
export type Opts = Options & {
|
|
60
|
+
/**
|
|
61
|
+
* 加密模式
|
|
62
|
+
*/
|
|
63
|
+
mode?: Mode;
|
|
64
|
+
};
|
|
65
|
+
export declare const _AES_: {
|
|
99
66
|
/**
|
|
100
67
|
* 获取允许的加密模式
|
|
101
68
|
*/
|
|
@@ -107,9 +74,7 @@ export type AES = typeof provders & {
|
|
|
107
74
|
* @param opts 加密套件参数
|
|
108
75
|
* @return 返回 Uint8Array 数据数组
|
|
109
76
|
*/
|
|
110
|
-
encrypt(key: string, text: string
|
|
111
|
-
mode?: Mode;
|
|
112
|
-
}): Uint8Array;
|
|
77
|
+
encrypt(key: string, text: string, opts?: Opts): Uint8Array;
|
|
113
78
|
/**
|
|
114
79
|
* 解密
|
|
115
80
|
* @param text 加密的内容 hex内容格式
|
|
@@ -117,9 +82,7 @@ export type AES = typeof provders & {
|
|
|
117
82
|
* @param opts 加密套件参数
|
|
118
83
|
* @return 返回 Uint8Array 数据数组
|
|
119
84
|
*/
|
|
120
|
-
decrypt(key: string, text: string
|
|
121
|
-
mode?: Mode;
|
|
122
|
-
}): Uint8Array;
|
|
85
|
+
decrypt(key: string, text: string, opts?: Opts): Uint8Array;
|
|
123
86
|
/**
|
|
124
87
|
* 加密密钥
|
|
125
88
|
* @param text 待加密内容
|
|
@@ -127,9 +90,7 @@ export type AES = typeof provders & {
|
|
|
127
90
|
* @param opts 加密套件参数
|
|
128
91
|
* @return 加密后的 hex 内容
|
|
129
92
|
*/
|
|
130
|
-
encode(key: string, text: string
|
|
131
|
-
mode?: Mode;
|
|
132
|
-
}): string;
|
|
93
|
+
encode(key: string, text: string, opts?: Opts): string;
|
|
133
94
|
/**
|
|
134
95
|
* 解密
|
|
135
96
|
* @param text 加密的内容 hex内容格式
|
|
@@ -137,15 +98,43 @@ export type AES = typeof provders & {
|
|
|
137
98
|
* @param opts 加密套件参数
|
|
138
99
|
* @return 解密后的字符串
|
|
139
100
|
*/
|
|
140
|
-
decode(key: string, text: string
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
101
|
+
decode(key: string, text: string, opts?: Opts): any;
|
|
102
|
+
ECB: {
|
|
103
|
+
/**
|
|
104
|
+
* ECB 模式 加密
|
|
105
|
+
* @param key 加密密钥
|
|
106
|
+
* @param plaintext 待加密的数据内容
|
|
107
|
+
* @param opts
|
|
108
|
+
*/
|
|
109
|
+
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding">): Uint8Array;
|
|
110
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding">): Uint8Array<ArrayBufferLike>;
|
|
111
|
+
encode(key: string, plaintext: string, opts?: Pick<Options, "padding">): string;
|
|
112
|
+
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding">): string;
|
|
113
|
+
};
|
|
114
|
+
CBC: {
|
|
115
|
+
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array;
|
|
116
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array<ArrayBufferLike>;
|
|
117
|
+
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
118
|
+
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
119
|
+
};
|
|
120
|
+
CFB: {
|
|
121
|
+
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): Uint8Array;
|
|
122
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): Uint8Array<ArrayBufferLike>;
|
|
123
|
+
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): string;
|
|
124
|
+
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv" | "segmentSize">): string;
|
|
125
|
+
};
|
|
126
|
+
OFB: {
|
|
127
|
+
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array;
|
|
128
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array<ArrayBufferLike>;
|
|
129
|
+
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
130
|
+
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
131
|
+
};
|
|
132
|
+
CTR: {
|
|
133
|
+
encrypt(key: string, plaintext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array;
|
|
134
|
+
decrypt(key: string, ciphertext: Uint8Array | Int8Array, opts?: Pick<Options, "padding" | "iv">): Uint8Array<ArrayBufferLike>;
|
|
135
|
+
encode(key: string, plaintext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
136
|
+
decode(key: string, ciphertext: string, opts?: Pick<Options, "padding" | "iv">): string;
|
|
137
|
+
};
|
|
149
138
|
};
|
|
150
|
-
export declare const _AES_: AES;
|
|
151
139
|
export default _AES_;
|
|
140
|
+
export declare type AES = typeof _AES_;
|
package/types/utils/Base64.d.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否为base64 内容
|
|
3
|
+
* @param str
|
|
4
|
+
*/
|
|
5
|
+
export declare function is(str: any): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* base64 加密
|
|
8
|
+
* @param input 需要解密的内容
|
|
9
|
+
*/
|
|
10
|
+
export declare function encode(input: any): string;
|
|
11
|
+
/**
|
|
12
|
+
* base64 解密
|
|
13
|
+
* @param input 待解密内容
|
|
14
|
+
*/
|
|
15
|
+
export declare function decode(input: any): string;
|
|
16
|
+
export declare function encrypt(input: any): Int8Array;
|
|
17
|
+
export declare function decrypt(input: any): Int8Array;
|
|
18
|
+
declare const _Base64_: {
|
|
2
19
|
/**
|
|
3
20
|
* 判断是否为base64 内容
|
|
4
21
|
* @param str
|
|
5
22
|
*/
|
|
6
|
-
is
|
|
23
|
+
is: typeof is;
|
|
7
24
|
/**
|
|
8
25
|
* base64 加密
|
|
9
26
|
* @param input 需要解密的内容
|
|
10
27
|
*/
|
|
11
|
-
encode
|
|
28
|
+
encode: typeof encode;
|
|
12
29
|
/**
|
|
13
30
|
* base64 解密
|
|
14
31
|
* @param input 待解密内容
|
|
15
32
|
*/
|
|
16
|
-
decode
|
|
33
|
+
decode: typeof decode;
|
|
17
34
|
/**
|
|
18
35
|
* 加密数据
|
|
19
36
|
* @param input
|
|
20
37
|
*/
|
|
21
|
-
|
|
38
|
+
decrypt: typeof decrypt;
|
|
22
39
|
/**
|
|
23
40
|
* 解密数据
|
|
24
41
|
* @param input
|
|
25
42
|
*/
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 判断是否为base64 内容
|
|
30
|
-
* @param str
|
|
31
|
-
*/
|
|
32
|
-
export declare function is(str: any): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* base64 加密
|
|
35
|
-
* @param input 需要解密的内容
|
|
36
|
-
*/
|
|
37
|
-
export declare function encode(input: any): string;
|
|
38
|
-
/**
|
|
39
|
-
* base64 解密
|
|
40
|
-
* @param input 待解密内容
|
|
41
|
-
*/
|
|
42
|
-
export declare function decode(input: any): string;
|
|
43
|
-
export declare function encrypt(input: any): Int8Array;
|
|
44
|
-
export declare function decrypt(input: any): Int8Array;
|
|
45
|
-
declare const _Base64_: Base64;
|
|
43
|
+
encrypt: typeof encrypt;
|
|
44
|
+
};
|
|
46
45
|
export default _Base64_;
|
|
46
|
+
export declare type Base64 = typeof _Base64_;
|
package/types/utils/Bytes.d.ts
CHANGED
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
export declare type Bytes = {
|
|
2
|
-
/**
|
|
3
|
-
* 将 数字 转换成 byte, [-128, 127]
|
|
4
|
-
* @param num
|
|
5
|
-
*/
|
|
6
|
-
byte(num: string | number): number;
|
|
7
|
-
/**
|
|
8
|
-
* 字符串转字节数组,
|
|
9
|
-
* @param str 字符串
|
|
10
|
-
*/
|
|
11
|
-
toBytes(str: string): Int8Array;
|
|
12
|
-
/**
|
|
13
|
-
* 字节数组转字符串
|
|
14
|
-
* @param {Int8Array|Uint8Array|[Number]} bytes 字节数组
|
|
15
|
-
*/
|
|
16
|
-
fromBytes(bytes: Int8Array | Uint8Array | [Number] | unknown): string;
|
|
17
|
-
/**
|
|
18
|
-
* 字符串转 16进制字符串
|
|
19
|
-
* @param str 字符串
|
|
20
|
-
*/
|
|
21
|
-
toHex(str: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* 将十六进制字符串 转化为 Int8Array
|
|
24
|
-
* @param hexs
|
|
25
|
-
*/
|
|
26
|
-
fromHex(hexs: string): Int8Array;
|
|
27
|
-
/**
|
|
28
|
-
* 字符串转 hex 字符串
|
|
29
|
-
* @param str
|
|
30
|
-
*/
|
|
31
|
-
str2hex(str: string): string;
|
|
32
|
-
/**
|
|
33
|
-
* 十六进制字符串转String
|
|
34
|
-
* @param hex
|
|
35
|
-
*/
|
|
36
|
-
hex2str(hex: string): string;
|
|
37
|
-
};
|
|
38
1
|
/**
|
|
39
2
|
* 字符串转字节数组,
|
|
40
3
|
* @param str 字符串
|
|
@@ -44,7 +7,7 @@ declare function toBytes(str: string): Int8Array;
|
|
|
44
7
|
* 字节数组转字符串
|
|
45
8
|
* @param {Int8Array|Uint8Array|[Number]} bytes 字节数组
|
|
46
9
|
*/
|
|
47
|
-
declare function fromBytes(bytes: Int8Array | Uint8Array | [
|
|
10
|
+
declare function fromBytes(bytes: Int8Array | Uint8Array | number[] | unknown): string;
|
|
48
11
|
/**
|
|
49
12
|
* 将 数字 转换成 byte, [-128, 127]
|
|
50
13
|
* @param num
|
|
@@ -59,7 +22,7 @@ declare function toHex(str: string | number | number[] | Int8Array | Uint8Array)
|
|
|
59
22
|
* 将十六进制字符串 转化为 Int8Array
|
|
60
23
|
* @param hexs
|
|
61
24
|
*/
|
|
62
|
-
declare function fromHex(hexs: string): Int8Array
|
|
25
|
+
declare function fromHex(hexs: string): Int8Array<ArrayBuffer>;
|
|
63
26
|
/**
|
|
64
27
|
* 十六进制字符串转String
|
|
65
28
|
* @param hex
|
|
@@ -70,6 +33,43 @@ declare function hex2str(hex: string): string;
|
|
|
70
33
|
* @param str
|
|
71
34
|
*/
|
|
72
35
|
declare function toUint8Array(str: string | Int8Array | Uint8Array | number[] | any): Uint8Array;
|
|
73
|
-
declare const _Bytes_:
|
|
36
|
+
declare const _Bytes_: {
|
|
37
|
+
/**
|
|
38
|
+
* 将 数字 转换成 byte, [-128, 127]
|
|
39
|
+
* @param num
|
|
40
|
+
*/
|
|
41
|
+
byte: typeof byte;
|
|
42
|
+
/**
|
|
43
|
+
* 字符串转字节数组,
|
|
44
|
+
* @param str 字符串
|
|
45
|
+
*/
|
|
46
|
+
toBytes: typeof toBytes;
|
|
47
|
+
/**
|
|
48
|
+
* 字节数组转字符串
|
|
49
|
+
* @param {Int8Array|Uint8Array|[Number]} bytes 字节数组
|
|
50
|
+
*/
|
|
51
|
+
fromBytes: typeof fromBytes;
|
|
52
|
+
/**
|
|
53
|
+
* 字符串转 16进制字符串
|
|
54
|
+
* @param str 字符串
|
|
55
|
+
*/
|
|
56
|
+
toHex: typeof toHex;
|
|
57
|
+
/**
|
|
58
|
+
* 将十六进制字符串 转化为 Int8Array
|
|
59
|
+
* @param hexs
|
|
60
|
+
*/
|
|
61
|
+
fromHex: typeof fromHex;
|
|
62
|
+
/**
|
|
63
|
+
* 字符串转 hex 字符串
|
|
64
|
+
* @param str
|
|
65
|
+
*/
|
|
66
|
+
str2hex: typeof toHex;
|
|
67
|
+
/**
|
|
68
|
+
* 十六进制字符串转String
|
|
69
|
+
* @param hex
|
|
70
|
+
*/
|
|
71
|
+
hex2str: typeof hex2str;
|
|
72
|
+
};
|
|
74
73
|
export { toBytes, fromBytes, toHex, hex2str, fromHex, byte, toUint8Array };
|
|
75
74
|
export default _Bytes_;
|
|
75
|
+
export type Bytes = typeof _Bytes_;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface ConsoleInstance {
|
|
2
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/assert_static) */
|
|
3
|
+
assert(condition?: boolean, ...data: any[]): void;
|
|
4
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/clear_static) */
|
|
5
|
+
clear(): void;
|
|
6
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/count_static) */
|
|
7
|
+
count(label?: string): void;
|
|
8
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/countReset_static) */
|
|
9
|
+
countReset(label?: string): void;
|
|
10
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug_static) */
|
|
11
|
+
debug(...data: any[]): void;
|
|
12
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dir_static) */
|
|
13
|
+
dir(item?: any, options?: any): void;
|
|
14
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dirxml_static) */
|
|
15
|
+
dirxml(...data: any[]): void;
|
|
16
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error_static) */
|
|
17
|
+
error(...data: any[]): void;
|
|
18
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/group_static) */
|
|
19
|
+
group(...data: any[]): void;
|
|
20
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupCollapsed_static) */
|
|
21
|
+
groupCollapsed(...data: any[]): void;
|
|
22
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupEnd_static) */
|
|
23
|
+
groupEnd(): void;
|
|
24
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/info_static) */
|
|
25
|
+
info(...data: any[]): void;
|
|
26
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static) */
|
|
27
|
+
log(...data: any[]): void;
|
|
28
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/table_static) */
|
|
29
|
+
table(tabularData?: any, properties?: string[]): void;
|
|
30
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/time_static) */
|
|
31
|
+
time(label?: string): void;
|
|
32
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeEnd_static) */
|
|
33
|
+
timeEnd(label?: string): void;
|
|
34
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeLog_static) */
|
|
35
|
+
timeLog(label?: string, ...data: any[]): void;
|
|
36
|
+
timeStamp(label?: string): void;
|
|
37
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/trace_static) */
|
|
38
|
+
trace(...data: any[]): void;
|
|
39
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/warn_static) */
|
|
40
|
+
warn(...data: any[]): void;
|
|
41
|
+
}
|
|
42
|
+
export declare const Console: any;
|
|
43
|
+
declare const _default: ConsoleInstance;
|
|
44
|
+
export default _default;
|
|
45
|
+
export declare const getNativeConsole: () => Console;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* 日期工具类
|
|
3
|
-
*/
|
|
4
|
-
export type DateUtils = {
|
|
1
|
+
declare const _DateUtils_: {
|
|
5
2
|
/**
|
|
6
3
|
* 指定日期获取值,返回格式 yyyy-MM-dd hh:mm:ss
|
|
7
4
|
* @param date 指定时间, 默认=当前时间
|
|
@@ -16,7 +13,7 @@ export type DateUtils = {
|
|
|
16
13
|
* 指定日期获取值,返回格式 yyyyMMdd
|
|
17
14
|
* @param date 指定时间, 默认=当前时间
|
|
18
15
|
*/
|
|
19
|
-
getDateInt(date?:
|
|
16
|
+
getDateInt(date?: any): string;
|
|
20
17
|
/**
|
|
21
18
|
* 日期格式化<br>
|
|
22
19
|
*
|
|
@@ -40,29 +37,28 @@ export type DateUtils = {
|
|
|
40
37
|
* @param fmt 格式内容
|
|
41
38
|
*/
|
|
42
39
|
format(date: Date, fmt: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* 解析时间
|
|
42
|
+
* @param s
|
|
43
|
+
* @param fmt
|
|
44
|
+
*/
|
|
45
|
+
parse(s: string | Date, fmt?: string): Date;
|
|
43
46
|
/**
|
|
44
47
|
* 获取时间差
|
|
45
48
|
* @param start 开始时间
|
|
46
49
|
* @param end 结束时间
|
|
47
50
|
*/
|
|
48
51
|
diff(start: string | Date, end?: string | Date): {
|
|
49
|
-
/**
|
|
50
|
-
* 天数差值
|
|
51
|
-
*/
|
|
52
52
|
day: number;
|
|
53
|
-
/**
|
|
54
|
-
* 0-24 小时
|
|
55
|
-
*/
|
|
56
53
|
hour: number;
|
|
57
|
-
/**
|
|
58
|
-
* 0-59
|
|
59
|
-
*/
|
|
60
54
|
minute: number;
|
|
61
|
-
/**
|
|
62
|
-
* 0-59
|
|
63
|
-
*/
|
|
64
55
|
second: number;
|
|
56
|
+
millisecond: number;
|
|
57
|
+
diff: number;
|
|
65
58
|
};
|
|
66
59
|
};
|
|
67
|
-
declare const _DateUtils_: DateUtils;
|
|
68
60
|
export default _DateUtils_;
|
|
61
|
+
/**
|
|
62
|
+
* 日期工具类
|
|
63
|
+
*/
|
|
64
|
+
export declare type DateUtils = typeof _DateUtils_;
|
package/types/utils/Env.d.ts
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export declare function set_exp_utils(tool: any): void;
|
|
2
|
+
declare const _ExpUtils_: {
|
|
3
|
+
defaultVars: {
|
|
4
|
+
Math: Math;
|
|
5
|
+
Date: DateConstructor;
|
|
6
|
+
RegExp: RegExpConstructor;
|
|
7
|
+
JSON: JSON;
|
|
8
|
+
String: StringConstructor;
|
|
9
|
+
Array: ArrayConstructor;
|
|
10
|
+
Object: ObjectConstructor;
|
|
11
|
+
Number: NumberConstructor;
|
|
12
|
+
Boolean: BooleanConstructor;
|
|
13
|
+
Function: FunctionConstructor;
|
|
14
|
+
Symbol: SymbolConstructor;
|
|
15
|
+
Map: MapConstructor;
|
|
16
|
+
WeakMap: WeakMapConstructor;
|
|
17
|
+
Set: SetConstructor;
|
|
18
|
+
WeakSet: WeakSetConstructor;
|
|
19
|
+
console: Console;
|
|
20
|
+
E: number;
|
|
21
|
+
LN10: number;
|
|
22
|
+
LN2: number;
|
|
23
|
+
LOG2E: number;
|
|
24
|
+
LOG10E: number;
|
|
25
|
+
PI: number;
|
|
26
|
+
SQRT1_2: number;
|
|
27
|
+
SQRT2: number;
|
|
28
|
+
abs(x: number): number;
|
|
29
|
+
acos(x: number): number;
|
|
30
|
+
asin(x: number): number;
|
|
31
|
+
atan(x: number): number;
|
|
32
|
+
atan2(y: number, x: number): number;
|
|
33
|
+
ceil(x: number): number;
|
|
34
|
+
cos(x: number): number;
|
|
35
|
+
exp(x: number): number;
|
|
36
|
+
floor(x: number): number;
|
|
37
|
+
log(x: number): number;
|
|
38
|
+
max(...values: number[]): number;
|
|
39
|
+
min(...values: number[]): number;
|
|
40
|
+
pow(x: number, y: number): number;
|
|
41
|
+
random(): number;
|
|
42
|
+
round(x: number): number;
|
|
43
|
+
sin(x: number): number;
|
|
44
|
+
sqrt(x: number): number;
|
|
45
|
+
tan(x: number): number;
|
|
46
|
+
clz32(x: number): number;
|
|
47
|
+
imul(x: number, y: number): number;
|
|
48
|
+
sign(x: number): number;
|
|
49
|
+
log10(x: number): number;
|
|
50
|
+
log2(x: number): number;
|
|
51
|
+
log1p(x: number): number;
|
|
52
|
+
expm1(x: number): number;
|
|
53
|
+
cosh(x: number): number;
|
|
54
|
+
sinh(x: number): number;
|
|
55
|
+
tanh(x: number): number;
|
|
56
|
+
acosh(x: number): number;
|
|
57
|
+
asinh(x: number): number;
|
|
58
|
+
atanh(x: number): number;
|
|
59
|
+
hypot(...values: number[]): number;
|
|
60
|
+
trunc(x: number): number;
|
|
61
|
+
fround(x: number): number;
|
|
62
|
+
cbrt(x: number): number;
|
|
63
|
+
f16round(x: number): number;
|
|
64
|
+
[Symbol.toStringTag]: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* 执行表达式
|
|
68
|
+
* @param expression 表达式文本
|
|
69
|
+
* @param params 运行参数
|
|
70
|
+
*/
|
|
71
|
+
execute(expression: string, params: Record<any, any>): any;
|
|
72
|
+
};
|
|
73
|
+
export default _ExpUtils_;
|
|
74
|
+
export type ExpUtils = typeof _ExpUtils_;
|