ly-utils-lib 1.0.12 → 2.5.0
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/LICENSE +21 -0
- package/README.md +1002 -685
- package/dist/array.cjs +237 -0
- package/dist/array.cjs.map +1 -0
- package/dist/array.d.cts +2 -0
- package/dist/array.d.ts +2 -0
- package/dist/array.js +150 -0
- package/dist/array.js.map +1 -0
- package/dist/crypto.cjs +193 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.d.cts +3 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +144 -0
- package/dist/crypto.js.map +1 -0
- package/dist/date.cjs +563 -0
- package/dist/date.cjs.map +1 -0
- package/dist/date.d.cts +2 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +451 -0
- package/dist/date.js.map +1 -0
- package/dist/excel.cjs +227 -0
- package/dist/excel.cjs.map +1 -0
- package/dist/excel.d.cts +2 -0
- package/dist/excel.d.ts +2 -0
- package/dist/excel.js +196 -0
- package/dist/excel.js.map +1 -0
- package/dist/index-B80SEVzM.d.cts +382 -0
- package/dist/index-B80SEVzM.d.ts +382 -0
- package/dist/index-Ba1rjTzj.d.cts +299 -0
- package/dist/index-Ba1rjTzj.d.ts +299 -0
- package/dist/index-Bg1ise7y.d.cts +253 -0
- package/dist/index-Bg1ise7y.d.ts +253 -0
- package/dist/index-BoqNpwNa.d.cts +203 -0
- package/dist/index-BoqNpwNa.d.ts +203 -0
- package/dist/index-C0qUnb9Y.d.cts +533 -0
- package/dist/index-C0qUnb9Y.d.ts +533 -0
- package/dist/index-Cq1GhjpY.d.cts +229 -0
- package/dist/index-Cq1GhjpY.d.ts +229 -0
- package/dist/index-Cy-mb5v_.d.cts +262 -0
- package/dist/index-Cy-mb5v_.d.ts +262 -0
- package/dist/index-D1f9Sym2.d.cts +148 -0
- package/dist/index-D1f9Sym2.d.ts +148 -0
- package/dist/index-Dan5oF-5.d.cts +213 -0
- package/dist/index-Dan5oF-5.d.ts +213 -0
- package/dist/index-XABfrs7z.d.cts +596 -0
- package/dist/index-XABfrs7z.d.ts +596 -0
- package/dist/index-YXWfKCK7.d.cts +109 -0
- package/dist/index-YXWfKCK7.d.ts +109 -0
- package/dist/index.cjs +3691 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +3629 -0
- package/dist/index.js.map +1 -0
- package/dist/map.cjs +839 -0
- package/dist/map.cjs.map +1 -0
- package/dist/map.d.cts +6 -0
- package/dist/map.d.ts +6 -0
- package/dist/map.js +811 -0
- package/dist/map.js.map +1 -0
- package/dist/object.cjs +316 -0
- package/dist/object.cjs.map +1 -0
- package/dist/object.d.cts +2 -0
- package/dist/object.d.ts +2 -0
- package/dist/object.js +247 -0
- package/dist/object.js.map +1 -0
- package/dist/pdf.cjs +197 -0
- package/dist/pdf.cjs.map +1 -0
- package/dist/pdf.d.cts +3 -0
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +173 -0
- package/dist/pdf.js.map +1 -0
- package/dist/storage.cjs +255 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +1 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.js +226 -0
- package/dist/storage.js.map +1 -0
- package/dist/string.cjs +232 -0
- package/dist/string.cjs.map +1 -0
- package/dist/string.d.cts +2 -0
- package/dist/string.d.ts +2 -0
- package/dist/string.js +170 -0
- package/dist/string.js.map +1 -0
- package/dist/utils.cjs +429 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +371 -0
- package/dist/utils.js.map +1 -0
- package/dist/websocket.cjs +338 -0
- package/dist/websocket.cjs.map +1 -0
- package/dist/websocket.d.cts +1 -0
- package/dist/websocket.d.ts +1 -0
- package/dist/websocket.js +330 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +159 -33
- package/dist/ly-utils-lib.cjs.js +0 -115
- package/dist/ly-utils-lib.cjs.js.map +0 -1
- package/dist/ly-utils-lib.es.js +0 -58589
- package/dist/ly-utils-lib.es.js.map +0 -1
- package/dist/ly-utils-lib.umd.js +0 -115
- package/dist/ly-utils-lib.umd.js.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/utils/esToolkit.d.ts +0 -2
- package/dist/types/utils/ol.d.ts +0 -175
- package/dist/types/utils/router.d.ts +0 -10
- package/dist/types/utils/storage.d.ts +0 -42
- package/dist/types/utils/time.d.ts +0 -66
- package/dist/types/utils/tool.d.ts +0 -80
- package/dist/vite.svg +0 -1
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import * as cryptoJs from 'crypto-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 加密解密模块
|
|
5
|
+
* 基于 crypto-js 提供常用的加密解密功能
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 加密模式类型
|
|
10
|
+
*/
|
|
11
|
+
type CryptoMode = any;
|
|
12
|
+
/**
|
|
13
|
+
* 填充方式类型
|
|
14
|
+
*/
|
|
15
|
+
type CryptoPadding = any;
|
|
16
|
+
/**
|
|
17
|
+
* MD5 加密
|
|
18
|
+
* @param message 要加密的消息
|
|
19
|
+
* @returns MD5 哈希值
|
|
20
|
+
*/
|
|
21
|
+
declare const md5: (message: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* SHA1 加密
|
|
24
|
+
* @param message 要加密的消息
|
|
25
|
+
* @returns SHA1 哈希值
|
|
26
|
+
*/
|
|
27
|
+
declare const sha1: (message: string) => string;
|
|
28
|
+
/**
|
|
29
|
+
* SHA256 加密
|
|
30
|
+
* @param message 要加密的消息
|
|
31
|
+
* @returns SHA256 哈希值
|
|
32
|
+
*/
|
|
33
|
+
declare const sha256: (message: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* SHA512 加密
|
|
36
|
+
* @param message 要加密的消息
|
|
37
|
+
* @returns SHA512 哈希值
|
|
38
|
+
*/
|
|
39
|
+
declare const sha512: (message: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Hmac-MD5 加密
|
|
42
|
+
* @param message 要加密的消息
|
|
43
|
+
* @param key 密钥
|
|
44
|
+
* @returns Hmac-MD5 哈希值
|
|
45
|
+
*/
|
|
46
|
+
declare const hmacMD5: (message: string, key: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Hmac-SHA1 加密
|
|
49
|
+
* @param message 要加密的消息
|
|
50
|
+
* @param key 密钥
|
|
51
|
+
* @returns Hmac-SHA1 哈希值
|
|
52
|
+
*/
|
|
53
|
+
declare const hmacSHA1: (message: string, key: string) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Hmac-SHA256 加密
|
|
56
|
+
* @param message 要加密的消息
|
|
57
|
+
* @param key 密钥
|
|
58
|
+
* @returns Hmac-SHA256 哈希值
|
|
59
|
+
*/
|
|
60
|
+
declare const hmacSHA256: (message: string, key: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* Hmac-SHA512 加密
|
|
63
|
+
* @param message 要加密的消息
|
|
64
|
+
* @param key 密钥
|
|
65
|
+
* @returns Hmac-SHA512 哈希值
|
|
66
|
+
*/
|
|
67
|
+
declare const hmacSHA512: (message: string, key: string) => string;
|
|
68
|
+
/**
|
|
69
|
+
* AES 加密
|
|
70
|
+
* @param message 要加密的消息
|
|
71
|
+
* @param key 密钥(16/24/32 字节)
|
|
72
|
+
* @param iv 初始向量(可选,16 字节)
|
|
73
|
+
* @param mode 加密模式(默认 CBC)
|
|
74
|
+
* @param padding 填充方式(默认 Pkcs7)
|
|
75
|
+
* @returns 加密后的密文(Base64 格式)
|
|
76
|
+
*/
|
|
77
|
+
declare const aesEncrypt: (message: string, key: string, iv?: string, mode?: CryptoMode, padding?: CryptoPadding) => string;
|
|
78
|
+
/**
|
|
79
|
+
* AES 解密
|
|
80
|
+
* @param ciphertext 密文(Base64 格式)
|
|
81
|
+
* @param key 密钥(16/24/32 字节)
|
|
82
|
+
* @param iv 初始向量(可选,16 字节)
|
|
83
|
+
* @param mode 加密模式(默认 CBC)
|
|
84
|
+
* @param padding 填充方式(默认 Pkcs7)
|
|
85
|
+
* @returns 解密后的明文
|
|
86
|
+
*/
|
|
87
|
+
declare const aesDecrypt: (ciphertext: string, key: string, iv?: string, mode?: CryptoMode, padding?: CryptoPadding) => string;
|
|
88
|
+
/**
|
|
89
|
+
* DES 加密
|
|
90
|
+
* @param message 要加密的消息
|
|
91
|
+
* @param key 密钥(8 字节)
|
|
92
|
+
* @param iv 初始向量(可选,8 字节)
|
|
93
|
+
* @param mode 加密模式(默认 CBC)
|
|
94
|
+
* @param padding 填充方式(默认 Pkcs7)
|
|
95
|
+
* @returns 加密后的密文(Base64 格式)
|
|
96
|
+
*/
|
|
97
|
+
declare const desEncrypt: (message: string, key: string, iv?: string, mode?: CryptoMode, padding?: CryptoPadding) => string;
|
|
98
|
+
/**
|
|
99
|
+
* DES 解密
|
|
100
|
+
* @param ciphertext 密文(Base64 格式)
|
|
101
|
+
* @param key 密钥(8 字节)
|
|
102
|
+
* @param iv 初始向量(可选,8 字节)
|
|
103
|
+
* @param mode 加密模式(默认 CBC)
|
|
104
|
+
* @param padding 填充方式(默认 Pkcs7)
|
|
105
|
+
* @returns 解密后的明文
|
|
106
|
+
*/
|
|
107
|
+
declare const desDecrypt: (ciphertext: string, key: string, iv?: string, mode?: CryptoMode, padding?: CryptoPadding) => string;
|
|
108
|
+
/**
|
|
109
|
+
* Triple DES (3DES) 加密
|
|
110
|
+
* @param message 要加密的消息
|
|
111
|
+
* @param key 密钥(24 字节)
|
|
112
|
+
* @param iv 初始向量(可选,8 字节)
|
|
113
|
+
* @param mode 加密模式(默认 CBC)
|
|
114
|
+
* @param padding 填充方式(默认 Pkcs7)
|
|
115
|
+
* @returns 加密后的密文(Base64 格式)
|
|
116
|
+
*/
|
|
117
|
+
declare const tripleDesEncrypt: (message: string, key: string, iv?: string, mode?: CryptoMode, padding?: CryptoPadding) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Triple DES (3DES) 解密
|
|
120
|
+
* @param ciphertext 密文(Base64 格式)
|
|
121
|
+
* @param key 密钥(24 字节)
|
|
122
|
+
* @param iv 初始向量(可选,8 字节)
|
|
123
|
+
* @param mode 加密模式(默认 CBC)
|
|
124
|
+
* @param padding 填充方式(默认 Pkcs7)
|
|
125
|
+
* @returns 解密后的明文
|
|
126
|
+
*/
|
|
127
|
+
declare const tripleDesDecrypt: (ciphertext: string, key: string, iv?: string, mode?: CryptoMode, padding?: CryptoPadding) => string;
|
|
128
|
+
/**
|
|
129
|
+
* RC4 加密
|
|
130
|
+
* @param message 要加密的消息
|
|
131
|
+
* @param key 密钥
|
|
132
|
+
* @returns 加密后的密文(Base64 格式)
|
|
133
|
+
*/
|
|
134
|
+
declare const rc4Encrypt: (message: string, key: string) => string;
|
|
135
|
+
/**
|
|
136
|
+
* RC4 解密
|
|
137
|
+
* @param ciphertext 密文(Base64 格式)
|
|
138
|
+
* @param key 密钥
|
|
139
|
+
* @returns 解密后的明文
|
|
140
|
+
*/
|
|
141
|
+
declare const rc4Decrypt: (ciphertext: string, key: string) => string;
|
|
142
|
+
/**
|
|
143
|
+
* Rabbit 加密
|
|
144
|
+
* @param message 要加密的消息
|
|
145
|
+
* @param key 密钥
|
|
146
|
+
* @returns 加密后的密文(Base64 格式)
|
|
147
|
+
*/
|
|
148
|
+
declare const rabbitEncrypt: (message: string, key: string) => string;
|
|
149
|
+
/**
|
|
150
|
+
* Rabbit 解密
|
|
151
|
+
* @param ciphertext 密文(Base64 格式)
|
|
152
|
+
* @param key 密钥
|
|
153
|
+
* @returns 解密后的明文
|
|
154
|
+
*/
|
|
155
|
+
declare const rabbitDecrypt: (ciphertext: string, key: string) => string;
|
|
156
|
+
/**
|
|
157
|
+
* Base64 编码
|
|
158
|
+
* @param message 要编码的消息
|
|
159
|
+
* @returns Base64 编码后的字符串
|
|
160
|
+
*/
|
|
161
|
+
declare const base64Encode: (message: string) => string;
|
|
162
|
+
/**
|
|
163
|
+
* Base64 解码
|
|
164
|
+
* @param encoded Base64 编码的字符串
|
|
165
|
+
* @returns 解码后的原始消息
|
|
166
|
+
*/
|
|
167
|
+
declare const base64Decode: (encoded: string) => string;
|
|
168
|
+
/**
|
|
169
|
+
* UTF-8 编码
|
|
170
|
+
* @param message 要编码的消息
|
|
171
|
+
* @returns UTF-8 编码后的字符串
|
|
172
|
+
*/
|
|
173
|
+
declare const utf8Encode: (message: string) => string;
|
|
174
|
+
/**
|
|
175
|
+
* UTF-8 解码
|
|
176
|
+
* @param encoded UTF-8 编码的字符串
|
|
177
|
+
* @returns 解码后的原始消息
|
|
178
|
+
*/
|
|
179
|
+
declare const utf8Decode: (encoded: string) => string;
|
|
180
|
+
/**
|
|
181
|
+
* Hex 编码
|
|
182
|
+
* @param message 要编码的消息
|
|
183
|
+
* @returns Hex 编码后的字符串
|
|
184
|
+
*/
|
|
185
|
+
declare const hexEncode: (message: string) => string;
|
|
186
|
+
/**
|
|
187
|
+
* Hex 解码
|
|
188
|
+
* @param encoded Hex 编码的字符串
|
|
189
|
+
* @returns 解码后的原始消息
|
|
190
|
+
*/
|
|
191
|
+
declare const hexDecode: (encoded: string) => string;
|
|
192
|
+
/**
|
|
193
|
+
* 生成随机密钥
|
|
194
|
+
* @param length 密钥长度(字节)
|
|
195
|
+
* @returns 随机密钥(Base64 格式)
|
|
196
|
+
*/
|
|
197
|
+
declare const generateKey: (length?: number) => string;
|
|
198
|
+
/**
|
|
199
|
+
* 生成随机 IV(初始向量)
|
|
200
|
+
* @param length IV 长度(字节,默认 16)
|
|
201
|
+
* @returns 随机 IV(Base64 格式)
|
|
202
|
+
*/
|
|
203
|
+
declare const generateIV: (length?: number) => string;
|
|
204
|
+
/**
|
|
205
|
+
* PBKDF2 密钥派生
|
|
206
|
+
* @param password 密码
|
|
207
|
+
* @param salt 盐值
|
|
208
|
+
* @param iterations 迭代次数
|
|
209
|
+
* @param keySize 密钥长度(字节)
|
|
210
|
+
* @returns 派生的密钥(Hex 格式)
|
|
211
|
+
*/
|
|
212
|
+
declare const pbkdf2: (password: string, salt: string, iterations?: number, keySize?: number) => string;
|
|
213
|
+
/**
|
|
214
|
+
* 生成 UUID v4
|
|
215
|
+
* @returns UUID 字符串
|
|
216
|
+
*/
|
|
217
|
+
declare const uuid: () => string;
|
|
218
|
+
|
|
219
|
+
type index_CryptoMode = CryptoMode;
|
|
220
|
+
type index_CryptoPadding = CryptoPadding;
|
|
221
|
+
declare const index_aesDecrypt: typeof aesDecrypt;
|
|
222
|
+
declare const index_aesEncrypt: typeof aesEncrypt;
|
|
223
|
+
declare const index_base64Decode: typeof base64Decode;
|
|
224
|
+
declare const index_base64Encode: typeof base64Encode;
|
|
225
|
+
declare const index_desDecrypt: typeof desDecrypt;
|
|
226
|
+
declare const index_desEncrypt: typeof desEncrypt;
|
|
227
|
+
declare const index_generateIV: typeof generateIV;
|
|
228
|
+
declare const index_generateKey: typeof generateKey;
|
|
229
|
+
declare const index_hexDecode: typeof hexDecode;
|
|
230
|
+
declare const index_hexEncode: typeof hexEncode;
|
|
231
|
+
declare const index_hmacMD5: typeof hmacMD5;
|
|
232
|
+
declare const index_hmacSHA1: typeof hmacSHA1;
|
|
233
|
+
declare const index_hmacSHA256: typeof hmacSHA256;
|
|
234
|
+
declare const index_hmacSHA512: typeof hmacSHA512;
|
|
235
|
+
declare const index_md5: typeof md5;
|
|
236
|
+
declare const index_pbkdf2: typeof pbkdf2;
|
|
237
|
+
declare const index_rabbitDecrypt: typeof rabbitDecrypt;
|
|
238
|
+
declare const index_rabbitEncrypt: typeof rabbitEncrypt;
|
|
239
|
+
declare const index_rc4Decrypt: typeof rc4Decrypt;
|
|
240
|
+
declare const index_rc4Encrypt: typeof rc4Encrypt;
|
|
241
|
+
declare const index_sha1: typeof sha1;
|
|
242
|
+
declare const index_sha256: typeof sha256;
|
|
243
|
+
declare const index_sha512: typeof sha512;
|
|
244
|
+
declare const index_tripleDesDecrypt: typeof tripleDesDecrypt;
|
|
245
|
+
declare const index_tripleDesEncrypt: typeof tripleDesEncrypt;
|
|
246
|
+
declare const index_utf8Decode: typeof utf8Decode;
|
|
247
|
+
declare const index_utf8Encode: typeof utf8Encode;
|
|
248
|
+
declare const index_uuid: typeof uuid;
|
|
249
|
+
declare namespace index {
|
|
250
|
+
export { cryptoJs as CryptoJS, type index_CryptoMode as CryptoMode, type index_CryptoPadding as CryptoPadding, index_aesDecrypt as aesDecrypt, index_aesEncrypt as aesEncrypt, index_base64Decode as base64Decode, index_base64Encode as base64Encode, index_desDecrypt as desDecrypt, index_desEncrypt as desEncrypt, index_generateIV as generateIV, index_generateKey as generateKey, index_hexDecode as hexDecode, index_hexEncode as hexEncode, index_hmacMD5 as hmacMD5, index_hmacSHA1 as hmacSHA1, index_hmacSHA256 as hmacSHA256, index_hmacSHA512 as hmacSHA512, index_md5 as md5, index_pbkdf2 as pbkdf2, index_rabbitDecrypt as rabbitDecrypt, index_rabbitEncrypt as rabbitEncrypt, index_rc4Decrypt as rc4Decrypt, index_rc4Encrypt as rc4Encrypt, index_sha1 as sha1, index_sha256 as sha256, index_sha512 as sha512, index_tripleDesDecrypt as tripleDesDecrypt, index_tripleDesEncrypt as tripleDesEncrypt, index_utf8Decode as utf8Decode, index_utf8Encode as utf8Encode, index_uuid as uuid };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export { tripleDesEncrypt as A, utf8Decode as B, type CryptoMode as C, utf8Encode as D, uuid as E, type CryptoPadding as a, aesDecrypt as b, aesEncrypt as c, base64Decode as d, base64Encode as e, desDecrypt as f, desEncrypt as g, generateIV as h, index as i, generateKey as j, hexDecode as k, hexEncode as l, hmacMD5 as m, hmacSHA1 as n, hmacSHA256 as o, hmacSHA512 as p, md5 as q, pbkdf2 as r, rabbitDecrypt as s, rabbitEncrypt as t, rc4Decrypt as u, rc4Encrypt as v, sha1 as w, sha256 as x, sha512 as y, tripleDesDecrypt as z };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { chunk, compact, difference, flatten, flattenDeep, groupBy, head, intersection, isEqual, last, omit, sample, sortBy, sum, uniq, uniqBy } from 'es-toolkit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 数组工具模块
|
|
5
|
+
* 基于 es-toolkit 封装,提供常用的数组处理功能
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 数组去重(支持对象数组的去重)
|
|
10
|
+
* @param arr 数组
|
|
11
|
+
* @param key 对象数组的去重键值
|
|
12
|
+
*/
|
|
13
|
+
declare const unique: <T>(arr: T[], key?: keyof T) => T[];
|
|
14
|
+
/**
|
|
15
|
+
* 获取数组最小值
|
|
16
|
+
* @param arr 数组
|
|
17
|
+
*/
|
|
18
|
+
declare const min: (arr: number[]) => number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* 获取数组最大值
|
|
21
|
+
* @param arr 数组
|
|
22
|
+
*/
|
|
23
|
+
declare const max: (arr: number[]) => number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* 判断数组是否为空
|
|
26
|
+
* @param arr 数组
|
|
27
|
+
*/
|
|
28
|
+
declare const isEmpty: <T>(arr: T[]) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 数组分割
|
|
31
|
+
* @param arr 数组
|
|
32
|
+
* @param size 每组大小
|
|
33
|
+
*/
|
|
34
|
+
declare const split: <T>(arr: T[], size: number) => T[][];
|
|
35
|
+
/**
|
|
36
|
+
* 数组乱序
|
|
37
|
+
* @param arr 数组
|
|
38
|
+
*/
|
|
39
|
+
declare const shuffle: <T>(arr: T[]) => T[];
|
|
40
|
+
/**
|
|
41
|
+
* 查找元素的索引
|
|
42
|
+
* @param arr 数组
|
|
43
|
+
* @param predicate 查找条件
|
|
44
|
+
*/
|
|
45
|
+
declare const findIndex: <T>(arr: T[], predicate: (item: T, index: number) => boolean) => number;
|
|
46
|
+
/**
|
|
47
|
+
* 查找元素
|
|
48
|
+
* @param arr 数组
|
|
49
|
+
* @param predicate 查找条件
|
|
50
|
+
*/
|
|
51
|
+
declare const find: <T>(arr: T[], predicate: (item: T, index: number) => boolean) => T | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* 过滤数组
|
|
54
|
+
* @param arr 数组
|
|
55
|
+
* @param predicate 过滤条件
|
|
56
|
+
*/
|
|
57
|
+
declare const filter: <T>(arr: T[], predicate: (item: T, index: number) => boolean) => T[];
|
|
58
|
+
/**
|
|
59
|
+
* 映射数组
|
|
60
|
+
* @param arr 数组
|
|
61
|
+
* @param mapper 映射函数
|
|
62
|
+
*/
|
|
63
|
+
declare const map: <T, R>(arr: T[], mapper: (item: T, index: number) => R) => R[];
|
|
64
|
+
/**
|
|
65
|
+
* 数组求和
|
|
66
|
+
* @param arr 数组
|
|
67
|
+
* @param mapper 转换函数
|
|
68
|
+
*/
|
|
69
|
+
declare const reduceSum: <T>(arr: T[], mapper?: (item: T) => number) => number;
|
|
70
|
+
/**
|
|
71
|
+
* 数组求平均值
|
|
72
|
+
* @param arr 数组
|
|
73
|
+
* @param mapper 转换函数
|
|
74
|
+
*/
|
|
75
|
+
declare const average: <T>(arr: T[], mapper?: (item: T) => number) => number;
|
|
76
|
+
/**
|
|
77
|
+
* 数组最大值
|
|
78
|
+
* @param arr 数组
|
|
79
|
+
* @param mapper 转换函数
|
|
80
|
+
*/
|
|
81
|
+
declare const maxValue: <T>(arr: T[], mapper?: (item: T) => number) => number | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* 数组最小值
|
|
84
|
+
* @param arr 数组
|
|
85
|
+
* @param mapper 转换函数
|
|
86
|
+
*/
|
|
87
|
+
declare const minValue: <T>(arr: T[], mapper?: (item: T) => number) => number | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* 判断数组是否包含某个元素
|
|
90
|
+
* @param arr 数组
|
|
91
|
+
* @param value 值
|
|
92
|
+
*/
|
|
93
|
+
declare const includes: <T>(arr: T[], value: T) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* 数组删除元素
|
|
96
|
+
* @param arr 数组
|
|
97
|
+
* @param value 值
|
|
98
|
+
*/
|
|
99
|
+
declare const remove: <T>(arr: T[], value: T) => T[];
|
|
100
|
+
/**
|
|
101
|
+
* 数组删除指定索引元素
|
|
102
|
+
* @param arr 数组
|
|
103
|
+
* @param index 索引
|
|
104
|
+
*/
|
|
105
|
+
declare const removeAt: <T>(arr: T[], index: number) => T[];
|
|
106
|
+
/**
|
|
107
|
+
* 数组插入元素
|
|
108
|
+
* @param arr 数组
|
|
109
|
+
* @param index 索引
|
|
110
|
+
* @param value 值
|
|
111
|
+
*/
|
|
112
|
+
declare const insert: <T>(arr: T[], index: number, value: T) => T[];
|
|
113
|
+
/**
|
|
114
|
+
* 数组移动元素
|
|
115
|
+
* @param arr 数组
|
|
116
|
+
* @param from 源索引
|
|
117
|
+
* @param to 目标索引
|
|
118
|
+
*/
|
|
119
|
+
declare const move: <T>(arr: T[], from: number, to: number) => T[];
|
|
120
|
+
/**
|
|
121
|
+
* 数组转树形结构
|
|
122
|
+
* @param arr 数组
|
|
123
|
+
* @param options 配置
|
|
124
|
+
*/
|
|
125
|
+
declare const arrayToTree: <T extends Record<string, any>>(arr: T[], options?: {
|
|
126
|
+
idKey?: string;
|
|
127
|
+
parentIdKey?: string;
|
|
128
|
+
childrenKey?: string;
|
|
129
|
+
}) => T[];
|
|
130
|
+
/**
|
|
131
|
+
* 树形结构转数组
|
|
132
|
+
* @param tree 树
|
|
133
|
+
* @param childrenKey 子节点键名
|
|
134
|
+
*/
|
|
135
|
+
declare const treeToArray: <T extends Record<string, any>>(tree: T[], childrenKey?: string) => T[];
|
|
136
|
+
/**
|
|
137
|
+
* 数组分页
|
|
138
|
+
* @param arr 数组
|
|
139
|
+
* @param page 页码(从1开始)
|
|
140
|
+
* @param pageSize 每页数量
|
|
141
|
+
*/
|
|
142
|
+
declare const paginate: <T>(arr: T[], page: number, pageSize: number) => T[];
|
|
143
|
+
/**
|
|
144
|
+
* 获取分页信息
|
|
145
|
+
* @param total 总数
|
|
146
|
+
* @param page 页码(从1开始)
|
|
147
|
+
* @param pageSize 每页数量
|
|
148
|
+
*/
|
|
149
|
+
declare const getPaginationInfo: (total: number, page: number, pageSize: number) => {
|
|
150
|
+
total: number;
|
|
151
|
+
page: number;
|
|
152
|
+
pageSize: number;
|
|
153
|
+
totalPages: number;
|
|
154
|
+
startIndex: number;
|
|
155
|
+
endIndex: number;
|
|
156
|
+
hasNext: boolean;
|
|
157
|
+
hasPrev: boolean;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
declare const index_arrayToTree: typeof arrayToTree;
|
|
161
|
+
declare const index_average: typeof average;
|
|
162
|
+
declare const index_chunk: typeof chunk;
|
|
163
|
+
declare const index_compact: typeof compact;
|
|
164
|
+
declare const index_difference: typeof difference;
|
|
165
|
+
declare const index_filter: typeof filter;
|
|
166
|
+
declare const index_find: typeof find;
|
|
167
|
+
declare const index_findIndex: typeof findIndex;
|
|
168
|
+
declare const index_flatten: typeof flatten;
|
|
169
|
+
declare const index_flattenDeep: typeof flattenDeep;
|
|
170
|
+
declare const index_getPaginationInfo: typeof getPaginationInfo;
|
|
171
|
+
declare const index_groupBy: typeof groupBy;
|
|
172
|
+
declare const index_head: typeof head;
|
|
173
|
+
declare const index_includes: typeof includes;
|
|
174
|
+
declare const index_insert: typeof insert;
|
|
175
|
+
declare const index_intersection: typeof intersection;
|
|
176
|
+
declare const index_isEmpty: typeof isEmpty;
|
|
177
|
+
declare const index_isEqual: typeof isEqual;
|
|
178
|
+
declare const index_last: typeof last;
|
|
179
|
+
declare const index_map: typeof map;
|
|
180
|
+
declare const index_max: typeof max;
|
|
181
|
+
declare const index_maxValue: typeof maxValue;
|
|
182
|
+
declare const index_min: typeof min;
|
|
183
|
+
declare const index_minValue: typeof minValue;
|
|
184
|
+
declare const index_move: typeof move;
|
|
185
|
+
declare const index_omit: typeof omit;
|
|
186
|
+
declare const index_paginate: typeof paginate;
|
|
187
|
+
declare const index_reduceSum: typeof reduceSum;
|
|
188
|
+
declare const index_remove: typeof remove;
|
|
189
|
+
declare const index_removeAt: typeof removeAt;
|
|
190
|
+
declare const index_sample: typeof sample;
|
|
191
|
+
declare const index_shuffle: typeof shuffle;
|
|
192
|
+
declare const index_sortBy: typeof sortBy;
|
|
193
|
+
declare const index_split: typeof split;
|
|
194
|
+
declare const index_sum: typeof sum;
|
|
195
|
+
declare const index_treeToArray: typeof treeToArray;
|
|
196
|
+
declare const index_uniq: typeof uniq;
|
|
197
|
+
declare const index_uniqBy: typeof uniqBy;
|
|
198
|
+
declare const index_unique: typeof unique;
|
|
199
|
+
declare namespace index {
|
|
200
|
+
export { index_arrayToTree as arrayToTree, index_average as average, index_chunk as chunk, index_compact as compact, index_difference as difference, index_filter as filter, index_find as find, index_findIndex as findIndex, index_flatten as flatten, index_flattenDeep as flattenDeep, index_getPaginationInfo as getPaginationInfo, index_groupBy as groupBy, index_head as head, index_includes as includes, index_insert as insert, index_intersection as intersection, index_isEmpty as isEmpty, index_isEqual as isEqual, index_last as last, index_map as map, index_max as max, index_maxValue as maxValue, index_min as min, index_minValue as minValue, index_move as move, index_omit as omit, index_paginate as paginate, index_reduceSum as reduceSum, index_remove as remove, index_removeAt as removeAt, index_sample as sample, index_shuffle as shuffle, index_sortBy as sortBy, index_split as split, index_sum as sum, index_treeToArray as treeToArray, index_uniq as uniq, index_uniqBy as uniqBy, index_unique as unique };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { arrayToTree as a, average as b, find as c, findIndex as d, includes as e, filter as f, getPaginationInfo as g, insert as h, index as i, isEmpty as j, max as k, maxValue as l, map as m, min as n, minValue as o, move as p, paginate as q, reduceSum as r, remove as s, removeAt as t, shuffle as u, split as v, treeToArray as w, unique as x };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { chunk, compact, difference, flatten, flattenDeep, groupBy, head, intersection, isEqual, last, omit, sample, sortBy, sum, uniq, uniqBy } from 'es-toolkit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 数组工具模块
|
|
5
|
+
* 基于 es-toolkit 封装,提供常用的数组处理功能
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 数组去重(支持对象数组的去重)
|
|
10
|
+
* @param arr 数组
|
|
11
|
+
* @param key 对象数组的去重键值
|
|
12
|
+
*/
|
|
13
|
+
declare const unique: <T>(arr: T[], key?: keyof T) => T[];
|
|
14
|
+
/**
|
|
15
|
+
* 获取数组最小值
|
|
16
|
+
* @param arr 数组
|
|
17
|
+
*/
|
|
18
|
+
declare const min: (arr: number[]) => number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* 获取数组最大值
|
|
21
|
+
* @param arr 数组
|
|
22
|
+
*/
|
|
23
|
+
declare const max: (arr: number[]) => number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* 判断数组是否为空
|
|
26
|
+
* @param arr 数组
|
|
27
|
+
*/
|
|
28
|
+
declare const isEmpty: <T>(arr: T[]) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 数组分割
|
|
31
|
+
* @param arr 数组
|
|
32
|
+
* @param size 每组大小
|
|
33
|
+
*/
|
|
34
|
+
declare const split: <T>(arr: T[], size: number) => T[][];
|
|
35
|
+
/**
|
|
36
|
+
* 数组乱序
|
|
37
|
+
* @param arr 数组
|
|
38
|
+
*/
|
|
39
|
+
declare const shuffle: <T>(arr: T[]) => T[];
|
|
40
|
+
/**
|
|
41
|
+
* 查找元素的索引
|
|
42
|
+
* @param arr 数组
|
|
43
|
+
* @param predicate 查找条件
|
|
44
|
+
*/
|
|
45
|
+
declare const findIndex: <T>(arr: T[], predicate: (item: T, index: number) => boolean) => number;
|
|
46
|
+
/**
|
|
47
|
+
* 查找元素
|
|
48
|
+
* @param arr 数组
|
|
49
|
+
* @param predicate 查找条件
|
|
50
|
+
*/
|
|
51
|
+
declare const find: <T>(arr: T[], predicate: (item: T, index: number) => boolean) => T | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* 过滤数组
|
|
54
|
+
* @param arr 数组
|
|
55
|
+
* @param predicate 过滤条件
|
|
56
|
+
*/
|
|
57
|
+
declare const filter: <T>(arr: T[], predicate: (item: T, index: number) => boolean) => T[];
|
|
58
|
+
/**
|
|
59
|
+
* 映射数组
|
|
60
|
+
* @param arr 数组
|
|
61
|
+
* @param mapper 映射函数
|
|
62
|
+
*/
|
|
63
|
+
declare const map: <T, R>(arr: T[], mapper: (item: T, index: number) => R) => R[];
|
|
64
|
+
/**
|
|
65
|
+
* 数组求和
|
|
66
|
+
* @param arr 数组
|
|
67
|
+
* @param mapper 转换函数
|
|
68
|
+
*/
|
|
69
|
+
declare const reduceSum: <T>(arr: T[], mapper?: (item: T) => number) => number;
|
|
70
|
+
/**
|
|
71
|
+
* 数组求平均值
|
|
72
|
+
* @param arr 数组
|
|
73
|
+
* @param mapper 转换函数
|
|
74
|
+
*/
|
|
75
|
+
declare const average: <T>(arr: T[], mapper?: (item: T) => number) => number;
|
|
76
|
+
/**
|
|
77
|
+
* 数组最大值
|
|
78
|
+
* @param arr 数组
|
|
79
|
+
* @param mapper 转换函数
|
|
80
|
+
*/
|
|
81
|
+
declare const maxValue: <T>(arr: T[], mapper?: (item: T) => number) => number | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* 数组最小值
|
|
84
|
+
* @param arr 数组
|
|
85
|
+
* @param mapper 转换函数
|
|
86
|
+
*/
|
|
87
|
+
declare const minValue: <T>(arr: T[], mapper?: (item: T) => number) => number | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* 判断数组是否包含某个元素
|
|
90
|
+
* @param arr 数组
|
|
91
|
+
* @param value 值
|
|
92
|
+
*/
|
|
93
|
+
declare const includes: <T>(arr: T[], value: T) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* 数组删除元素
|
|
96
|
+
* @param arr 数组
|
|
97
|
+
* @param value 值
|
|
98
|
+
*/
|
|
99
|
+
declare const remove: <T>(arr: T[], value: T) => T[];
|
|
100
|
+
/**
|
|
101
|
+
* 数组删除指定索引元素
|
|
102
|
+
* @param arr 数组
|
|
103
|
+
* @param index 索引
|
|
104
|
+
*/
|
|
105
|
+
declare const removeAt: <T>(arr: T[], index: number) => T[];
|
|
106
|
+
/**
|
|
107
|
+
* 数组插入元素
|
|
108
|
+
* @param arr 数组
|
|
109
|
+
* @param index 索引
|
|
110
|
+
* @param value 值
|
|
111
|
+
*/
|
|
112
|
+
declare const insert: <T>(arr: T[], index: number, value: T) => T[];
|
|
113
|
+
/**
|
|
114
|
+
* 数组移动元素
|
|
115
|
+
* @param arr 数组
|
|
116
|
+
* @param from 源索引
|
|
117
|
+
* @param to 目标索引
|
|
118
|
+
*/
|
|
119
|
+
declare const move: <T>(arr: T[], from: number, to: number) => T[];
|
|
120
|
+
/**
|
|
121
|
+
* 数组转树形结构
|
|
122
|
+
* @param arr 数组
|
|
123
|
+
* @param options 配置
|
|
124
|
+
*/
|
|
125
|
+
declare const arrayToTree: <T extends Record<string, any>>(arr: T[], options?: {
|
|
126
|
+
idKey?: string;
|
|
127
|
+
parentIdKey?: string;
|
|
128
|
+
childrenKey?: string;
|
|
129
|
+
}) => T[];
|
|
130
|
+
/**
|
|
131
|
+
* 树形结构转数组
|
|
132
|
+
* @param tree 树
|
|
133
|
+
* @param childrenKey 子节点键名
|
|
134
|
+
*/
|
|
135
|
+
declare const treeToArray: <T extends Record<string, any>>(tree: T[], childrenKey?: string) => T[];
|
|
136
|
+
/**
|
|
137
|
+
* 数组分页
|
|
138
|
+
* @param arr 数组
|
|
139
|
+
* @param page 页码(从1开始)
|
|
140
|
+
* @param pageSize 每页数量
|
|
141
|
+
*/
|
|
142
|
+
declare const paginate: <T>(arr: T[], page: number, pageSize: number) => T[];
|
|
143
|
+
/**
|
|
144
|
+
* 获取分页信息
|
|
145
|
+
* @param total 总数
|
|
146
|
+
* @param page 页码(从1开始)
|
|
147
|
+
* @param pageSize 每页数量
|
|
148
|
+
*/
|
|
149
|
+
declare const getPaginationInfo: (total: number, page: number, pageSize: number) => {
|
|
150
|
+
total: number;
|
|
151
|
+
page: number;
|
|
152
|
+
pageSize: number;
|
|
153
|
+
totalPages: number;
|
|
154
|
+
startIndex: number;
|
|
155
|
+
endIndex: number;
|
|
156
|
+
hasNext: boolean;
|
|
157
|
+
hasPrev: boolean;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
declare const index_arrayToTree: typeof arrayToTree;
|
|
161
|
+
declare const index_average: typeof average;
|
|
162
|
+
declare const index_chunk: typeof chunk;
|
|
163
|
+
declare const index_compact: typeof compact;
|
|
164
|
+
declare const index_difference: typeof difference;
|
|
165
|
+
declare const index_filter: typeof filter;
|
|
166
|
+
declare const index_find: typeof find;
|
|
167
|
+
declare const index_findIndex: typeof findIndex;
|
|
168
|
+
declare const index_flatten: typeof flatten;
|
|
169
|
+
declare const index_flattenDeep: typeof flattenDeep;
|
|
170
|
+
declare const index_getPaginationInfo: typeof getPaginationInfo;
|
|
171
|
+
declare const index_groupBy: typeof groupBy;
|
|
172
|
+
declare const index_head: typeof head;
|
|
173
|
+
declare const index_includes: typeof includes;
|
|
174
|
+
declare const index_insert: typeof insert;
|
|
175
|
+
declare const index_intersection: typeof intersection;
|
|
176
|
+
declare const index_isEmpty: typeof isEmpty;
|
|
177
|
+
declare const index_isEqual: typeof isEqual;
|
|
178
|
+
declare const index_last: typeof last;
|
|
179
|
+
declare const index_map: typeof map;
|
|
180
|
+
declare const index_max: typeof max;
|
|
181
|
+
declare const index_maxValue: typeof maxValue;
|
|
182
|
+
declare const index_min: typeof min;
|
|
183
|
+
declare const index_minValue: typeof minValue;
|
|
184
|
+
declare const index_move: typeof move;
|
|
185
|
+
declare const index_omit: typeof omit;
|
|
186
|
+
declare const index_paginate: typeof paginate;
|
|
187
|
+
declare const index_reduceSum: typeof reduceSum;
|
|
188
|
+
declare const index_remove: typeof remove;
|
|
189
|
+
declare const index_removeAt: typeof removeAt;
|
|
190
|
+
declare const index_sample: typeof sample;
|
|
191
|
+
declare const index_shuffle: typeof shuffle;
|
|
192
|
+
declare const index_sortBy: typeof sortBy;
|
|
193
|
+
declare const index_split: typeof split;
|
|
194
|
+
declare const index_sum: typeof sum;
|
|
195
|
+
declare const index_treeToArray: typeof treeToArray;
|
|
196
|
+
declare const index_uniq: typeof uniq;
|
|
197
|
+
declare const index_uniqBy: typeof uniqBy;
|
|
198
|
+
declare const index_unique: typeof unique;
|
|
199
|
+
declare namespace index {
|
|
200
|
+
export { index_arrayToTree as arrayToTree, index_average as average, index_chunk as chunk, index_compact as compact, index_difference as difference, index_filter as filter, index_find as find, index_findIndex as findIndex, index_flatten as flatten, index_flattenDeep as flattenDeep, index_getPaginationInfo as getPaginationInfo, index_groupBy as groupBy, index_head as head, index_includes as includes, index_insert as insert, index_intersection as intersection, index_isEmpty as isEmpty, index_isEqual as isEqual, index_last as last, index_map as map, index_max as max, index_maxValue as maxValue, index_min as min, index_minValue as minValue, index_move as move, index_omit as omit, index_paginate as paginate, index_reduceSum as reduceSum, index_remove as remove, index_removeAt as removeAt, index_sample as sample, index_shuffle as shuffle, index_sortBy as sortBy, index_split as split, index_sum as sum, index_treeToArray as treeToArray, index_uniq as uniq, index_uniqBy as uniqBy, index_unique as unique };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { arrayToTree as a, average as b, find as c, findIndex as d, includes as e, filter as f, getPaginationInfo as g, insert as h, index as i, isEmpty as j, max as k, maxValue as l, map as m, min as n, minValue as o, move as p, paginate as q, reduceSum as r, remove as s, removeAt as t, shuffle as u, split as v, treeToArray as w, unique as x };
|