@szkj/utils 0.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,1698 @@
1
+ import CryptoJS from 'crypto-js';
2
+ import smCrypto from 'sm-crypto';
3
+
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
10
+
11
+ // src/mask/maskOptions.ts
12
+ function maskByKeepEnds(value, defaults, options = {}) {
13
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14
+ const start = normalizeCount(
15
+ (_b = (_a = options.start) != null ? _a : defaults.start) != null ? _b : 0
16
+ );
17
+ const end = normalizeCount(
18
+ (_d = (_c = options.end) != null ? _c : defaults.end) != null ? _d : 0
19
+ );
20
+ const maskChar = options.maskChar || defaults.maskChar || "*";
21
+ if (value.length <= start + end) {
22
+ const hiddenLength2 = Math.max(
23
+ value.length - start,
24
+ 0
25
+ );
26
+ const maskLength2 = normalizeCount(
27
+ (_f = (_e = options.maskLength) != null ? _e : defaults.maskLength) != null ? _f : hiddenLength2
28
+ );
29
+ return value.slice(0, start) + maskChar.repeat(maskLength2);
30
+ }
31
+ const hiddenLength = Math.max(
32
+ value.length - start - end,
33
+ 0
34
+ );
35
+ const maskLength = normalizeCount(
36
+ (_h = (_g = options.maskLength) != null ? _g : defaults.maskLength) != null ? _h : hiddenLength
37
+ );
38
+ return value.slice(0, start) + maskChar.repeat(maskLength) + (end > 0 ? value.slice(-end) : "");
39
+ }
40
+ function normalizeCount(value) {
41
+ return Math.max(0, Math.floor(value));
42
+ }
43
+
44
+ // src/mask/mask.ts
45
+ function mask(value, options = {}) {
46
+ if (!value) return "";
47
+ if (options.pattern) {
48
+ return maskByPattern(value, options);
49
+ }
50
+ if (options.range) {
51
+ return maskByRange(value, options);
52
+ }
53
+ return maskByKeepEnds(value, {}, options);
54
+ }
55
+ function maskByPattern(value, options) {
56
+ const {
57
+ pattern,
58
+ replacement,
59
+ maskChar = "*"
60
+ } = options;
61
+ if (!pattern) return value;
62
+ return value.replace(pattern, (match) => {
63
+ if (typeof replacement === "function") {
64
+ return replacement(match);
65
+ }
66
+ if (typeof replacement === "string") {
67
+ return replacement;
68
+ }
69
+ return maskChar.repeat(
70
+ getMaskLength(match.length, options)
71
+ );
72
+ });
73
+ }
74
+ function maskByRange(value, options) {
75
+ const [rawStart, rawEnd] = options.range || [0, 0];
76
+ const start = clampIndex(rawStart, value.length);
77
+ const end = clampIndex(rawEnd, value.length);
78
+ const from = Math.min(start, end);
79
+ const to = Math.max(start, end);
80
+ const maskChar = options.maskChar || "*";
81
+ return value.slice(0, from) + maskChar.repeat(
82
+ getMaskLength(to - from, options)
83
+ ) + value.slice(to);
84
+ }
85
+ function getMaskLength(hiddenLength, options) {
86
+ var _a;
87
+ return Math.max(
88
+ 0,
89
+ Math.floor(
90
+ (_a = options.maskLength) != null ? _a : hiddenLength
91
+ )
92
+ );
93
+ }
94
+ function clampIndex(value, length) {
95
+ return Math.min(
96
+ Math.max(0, Math.floor(value)),
97
+ length
98
+ );
99
+ }
100
+
101
+ // src/mask/maskName.ts
102
+ function maskName(name, options) {
103
+ if (!name) return "";
104
+ return maskByKeepEnds(
105
+ name,
106
+ {
107
+ start: 1,
108
+ end: 1,
109
+ maskChar: "*"
110
+ },
111
+ options
112
+ );
113
+ }
114
+
115
+ // src/mask/maskPhone.ts
116
+ function maskPhone(phone, options) {
117
+ if (!phone) return "";
118
+ if (!/^\d{11}$/.test(phone)) return phone;
119
+ return maskByKeepEnds(
120
+ phone,
121
+ {
122
+ start: 3,
123
+ end: 4,
124
+ maskChar: "*",
125
+ maskLength: 4
126
+ },
127
+ options
128
+ );
129
+ }
130
+
131
+ // src/mask/maskFixedPhone.ts
132
+ function maskFixedPhone(phone, options) {
133
+ if (!phone) return "";
134
+ const normalized = phone.replace(/[\s-]/g, "");
135
+ if (!/^\d{10,12}$/.test(normalized)) {
136
+ return phone;
137
+ }
138
+ const areaCodeLength = getAreaCodeLength(
139
+ phone,
140
+ normalized
141
+ );
142
+ return maskByKeepEnds(
143
+ normalized,
144
+ {
145
+ start: areaCodeLength,
146
+ end: 4,
147
+ maskChar: "*"
148
+ },
149
+ options
150
+ );
151
+ }
152
+ function getAreaCodeLength(phone, normalized) {
153
+ const areaCodeMatch = phone.match(/^(\d{3,4})-/);
154
+ if (areaCodeMatch) {
155
+ return areaCodeMatch[1].length;
156
+ }
157
+ if (normalized.length === 10) {
158
+ return 3;
159
+ }
160
+ return isThreeDigitAreaCode(normalized) ? 3 : 4;
161
+ }
162
+ function isThreeDigitAreaCode(value) {
163
+ return /^(010|020|021|022|023|024|025|027|028|029)/.test(
164
+ value
165
+ );
166
+ }
167
+
168
+ // src/mask/maskEmail.ts
169
+ function maskEmail(email, options) {
170
+ if (!email) return "";
171
+ const [name, domain] = email.split("@");
172
+ if (!name || !domain) return email;
173
+ const masked = maskByKeepEnds(
174
+ name,
175
+ {
176
+ start: 2,
177
+ end: 0,
178
+ maskChar: "*",
179
+ maskLength: 4
180
+ },
181
+ options
182
+ );
183
+ return `${masked}@${domain}`;
184
+ }
185
+
186
+ // src/mask/maskIdCard.ts
187
+ function maskIdCard(idCard, options) {
188
+ if (!idCard) return "";
189
+ if (idCard.length <= 8) return idCard;
190
+ return maskByKeepEnds(
191
+ idCard,
192
+ {
193
+ start: 4,
194
+ end: 4,
195
+ maskChar: "*",
196
+ maskLength: 10
197
+ },
198
+ options
199
+ );
200
+ }
201
+
202
+ // src/mask/maskBankCard.ts
203
+ function maskBankCard(cardNo, options) {
204
+ if (!cardNo) return "";
205
+ const normalized = cardNo.replace(/[\s-]/g, "");
206
+ if (!/^\d{10,30}$/.test(normalized)) {
207
+ return cardNo;
208
+ }
209
+ return maskByKeepEnds(
210
+ normalized,
211
+ {
212
+ start: 6,
213
+ end: 4,
214
+ maskChar: "*"
215
+ },
216
+ options
217
+ );
218
+ }
219
+
220
+ // src/mask/maskAddress.ts
221
+ function maskAddress(address, options = {}) {
222
+ var _a, _b;
223
+ if (!address) return "";
224
+ const keepLength = (_a = options.keepLength) != null ? _a : getRegionEndIndex(address);
225
+ const maskChar = options.maskChar || "*";
226
+ const maskLength = Math.max(
227
+ 0,
228
+ Math.floor((_b = options.maskLength) != null ? _b : 4)
229
+ );
230
+ return address.slice(0, keepLength) + maskChar.repeat(maskLength);
231
+ }
232
+ function getRegionEndIndex(address) {
233
+ const regionMatch = address.match(
234
+ /^(.+?(省|自治区|特别行政区))?(.+?(市|自治州|地区|盟))?(.+?(区|县|自治县|旗|自治旗|市))/
235
+ );
236
+ if (regionMatch) {
237
+ return regionMatch[0].length;
238
+ }
239
+ return Math.min(6, address.length);
240
+ }
241
+
242
+ // src/mask/maskPassport.ts
243
+ function maskPassport(passport, options) {
244
+ if (!passport) return "";
245
+ return maskByKeepEnds(
246
+ passport,
247
+ {
248
+ start: 2,
249
+ end: 2,
250
+ maskChar: "*"
251
+ },
252
+ options
253
+ );
254
+ }
255
+
256
+ // src/mask/maskCarPlate.ts
257
+ function maskCarPlate(plate, options) {
258
+ if (!plate) return "";
259
+ return maskByKeepEnds(
260
+ plate,
261
+ {
262
+ start: 2,
263
+ end: 1,
264
+ maskChar: "*"
265
+ },
266
+ options
267
+ );
268
+ }
269
+
270
+ // src/mask/maskIp.ts
271
+ function maskIp(ip, options = {}) {
272
+ if (!ip) return "";
273
+ if (ip.includes(":")) {
274
+ return maskIpv6(ip, options);
275
+ }
276
+ return maskIpv4(ip, options);
277
+ }
278
+ function maskIpv4(ip, options) {
279
+ var _a;
280
+ const segments = ip.split(".");
281
+ if (segments.length !== 4 || segments.some((segment) => !isIpv4Segment(segment))) {
282
+ return ip;
283
+ }
284
+ const target = Math.min(
285
+ Math.max((_a = options.segment) != null ? _a : 3, 0),
286
+ 3
287
+ );
288
+ segments[target] = options.maskChar || "*";
289
+ return segments.join(".");
290
+ }
291
+ function maskIpv6(ip, options) {
292
+ var _a;
293
+ const segments = ip.split(":");
294
+ if (segments.length < 3) return ip;
295
+ const target = Math.min(
296
+ Math.max(
297
+ (_a = options.segment) != null ? _a : segments.length - 1,
298
+ 0
299
+ ),
300
+ segments.length - 1
301
+ );
302
+ segments[target] = options.maskChar || "*";
303
+ return segments.join(":");
304
+ }
305
+ function isIpv4Segment(segment) {
306
+ if (!/^\d+$/.test(segment)) return false;
307
+ const value = Number(segment);
308
+ return value >= 0 && value <= 255;
309
+ }
310
+
311
+ // src/mask/maskAccount.ts
312
+ function maskAccount(account, options) {
313
+ if (!account) return "";
314
+ return maskByKeepEnds(
315
+ account,
316
+ {
317
+ start: 2,
318
+ end: 2,
319
+ maskChar: "*"
320
+ },
321
+ options
322
+ );
323
+ }
324
+
325
+ // src/mask/maskSecret.ts
326
+ function maskSecret(secret, options) {
327
+ if (!secret) return "";
328
+ return maskByKeepEnds(
329
+ secret,
330
+ {
331
+ start: 4,
332
+ end: 4,
333
+ maskChar: "*",
334
+ maskLength: 6
335
+ },
336
+ options
337
+ );
338
+ }
339
+
340
+ // src/regexp/index.ts
341
+ var REGEXP_PHONE = /^1[3-9]\d{9}$/;
342
+ var REGEXP_FIXED_PHONE = /^0\d{2,3}-?\d{7,8}$/;
343
+ var REGEXP_EMAIL = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
344
+ var REGEXP_ID_CARD = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
345
+ var REGEXP_BANK_CARD = /^\d{10,30}$/;
346
+ var REGEXP_PASSPORT = /^([A-Za-z]\d{8}|[A-Za-z]{2}\d{7})$/;
347
+ var REGEXP_CAR_PLATE = /^[\u4e00-\u9fa5][A-Z][A-Z0-9]{5,6}$/;
348
+ var REGEXP_URL = /^https?:\/\/[^\s/$.?#].[^\s]*$/i;
349
+ var REGEXP_IPV4 = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/;
350
+ var REGEXP_IPV6 = /^(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|(([0-9A-Fa-f]{1,4}:){1,7}:)|(([0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,5}(:[0-9A-Fa-f]{1,4}){1,2})|(([0-9A-Fa-f]{1,4}:){1,4}(:[0-9A-Fa-f]{1,4}){1,3})|(([0-9A-Fa-f]{1,4}:){1,3}(:[0-9A-Fa-f]{1,4}){1,4})|(([0-9A-Fa-f]{1,4}:){1,2}(:[0-9A-Fa-f]{1,4}){1,5})|([0-9A-Fa-f]{1,4}:)((:[0-9A-Fa-f]{1,4}){1,6})|:(:([0-9A-Fa-f]{1,4}){1,7}|:))$/;
351
+ var REGEXP_PORT = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
352
+ var REGEXP_CHINESE = /^[\u4e00-\u9fa5]+$/;
353
+ var REGEXP_POSTAL_CODE = /^[1-9]\d{5}$/;
354
+ var REGEXP_QQ = /^[1-9]\d{4,10}$/;
355
+ var REGEXP_USERNAME = /^[A-Za-z][A-Za-z0-9_]{3,19}$/;
356
+ var REGEXP_PASSWORD = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d\S]{8,20}$/;
357
+ var REGEXP_STRONG_PASSWORD = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,20}$/;
358
+ var REGEXP_INTEGER = /^-?\d+$/;
359
+ var REGEXP_POSITIVE_INTEGER = /^[1-9]\d*$/;
360
+ var REGEXP_DECIMAL = /^-?(0|[1-9]\d*)(\.\d+)?$/;
361
+ var REGEXP_AMOUNT = /^(0|[1-9]\d*)(\.\d{1,2})?$/;
362
+ var regexp = {
363
+ phone: REGEXP_PHONE,
364
+ fixedPhone: REGEXP_FIXED_PHONE,
365
+ email: REGEXP_EMAIL,
366
+ idCard: REGEXP_ID_CARD,
367
+ bankCard: REGEXP_BANK_CARD,
368
+ passport: REGEXP_PASSPORT,
369
+ carPlate: REGEXP_CAR_PLATE,
370
+ url: REGEXP_URL,
371
+ ipv4: REGEXP_IPV4,
372
+ ipv6: REGEXP_IPV6,
373
+ port: REGEXP_PORT,
374
+ chinese: REGEXP_CHINESE,
375
+ postalCode: REGEXP_POSTAL_CODE,
376
+ qq: REGEXP_QQ,
377
+ username: REGEXP_USERNAME,
378
+ password: REGEXP_PASSWORD,
379
+ strongPassword: REGEXP_STRONG_PASSWORD,
380
+ integer: REGEXP_INTEGER,
381
+ positiveInteger: REGEXP_POSITIVE_INTEGER,
382
+ decimal: REGEXP_DECIMAL,
383
+ amount: REGEXP_AMOUNT
384
+ };
385
+ function testRegexp(value, pattern) {
386
+ pattern.lastIndex = 0;
387
+ return pattern.test(value);
388
+ }
389
+ var isPhone = (value) => testRegexp(value, REGEXP_PHONE);
390
+ var isFixedPhone = (value) => testRegexp(value, REGEXP_FIXED_PHONE);
391
+ var isEmail = (value) => testRegexp(value, REGEXP_EMAIL);
392
+ var isIdCard = (value) => testRegexp(value, REGEXP_ID_CARD);
393
+ var isBankCard = (value) => testRegexp(value, REGEXP_BANK_CARD);
394
+ var isPassport = (value) => testRegexp(value, REGEXP_PASSPORT);
395
+ var isCarPlate = (value) => testRegexp(value, REGEXP_CAR_PLATE);
396
+ var isUrl = (value) => testRegexp(value, REGEXP_URL);
397
+ var isIpv4 = (value) => testRegexp(value, REGEXP_IPV4);
398
+ var isIpv6 = (value) => testRegexp(value, REGEXP_IPV6);
399
+ var isPort = (value) => testRegexp(value, REGEXP_PORT);
400
+ var isChinese = (value) => testRegexp(value, REGEXP_CHINESE);
401
+ var isPostalCode = (value) => testRegexp(value, REGEXP_POSTAL_CODE);
402
+ var isQq = (value) => testRegexp(value, REGEXP_QQ);
403
+ var isUsername = (value) => testRegexp(value, REGEXP_USERNAME);
404
+ var isPassword = (value) => testRegexp(value, REGEXP_PASSWORD);
405
+ var isStrongPassword = (value) => testRegexp(value, REGEXP_STRONG_PASSWORD);
406
+ var isInteger = (value) => testRegexp(value, REGEXP_INTEGER);
407
+ var isPositiveInteger = (value) => testRegexp(value, REGEXP_POSITIVE_INTEGER);
408
+ var isDecimal = (value) => testRegexp(value, REGEXP_DECIMAL);
409
+ var isAmount = (value) => testRegexp(value, REGEXP_AMOUNT);
410
+
411
+ // src/cache/index.ts
412
+ function createCache(options = {}) {
413
+ var _a;
414
+ const prefix = (_a = options.prefix) != null ? _a : "szkj:cache:";
415
+ const memory = /* @__PURE__ */ new Map();
416
+ const resolveKey = (key) => `${prefix}${key}`;
417
+ const unresolveKey = (key) => key.startsWith(prefix) ? key.slice(prefix.length) : key;
418
+ const getExpiresAt = (ttl = options.ttl) => {
419
+ if (typeof ttl !== "number") return null;
420
+ return Date.now() + Math.max(0, ttl);
421
+ };
422
+ const read = (resolvedKey) => {
423
+ if (!options.storage) {
424
+ return memory.get(resolvedKey);
425
+ }
426
+ const raw = options.storage.getItem(resolvedKey);
427
+ if (!raw) return void 0;
428
+ try {
429
+ return JSON.parse(raw);
430
+ } catch {
431
+ options.storage.removeItem(resolvedKey);
432
+ return void 0;
433
+ }
434
+ };
435
+ const write = (resolvedKey, record) => {
436
+ if (!options.storage) {
437
+ memory.set(resolvedKey, record);
438
+ return;
439
+ }
440
+ options.storage.setItem(
441
+ resolvedKey,
442
+ JSON.stringify(record)
443
+ );
444
+ };
445
+ const removeResolved = (resolvedKey) => {
446
+ if (!options.storage) {
447
+ memory.delete(resolvedKey);
448
+ return;
449
+ }
450
+ options.storage.removeItem(resolvedKey);
451
+ };
452
+ const isExpired = (record) => typeof record.expiresAt === "number" && record.expiresAt <= Date.now();
453
+ const getResolvedKeys = () => {
454
+ if (!options.storage) {
455
+ return Array.from(memory.keys()).filter(
456
+ (key) => key.startsWith(prefix)
457
+ );
458
+ }
459
+ const keys2 = [];
460
+ for (let index = 0; index < options.storage.length; index += 1) {
461
+ const key = options.storage.key(index);
462
+ if (key == null ? void 0 : key.startsWith(prefix)) {
463
+ keys2.push(key);
464
+ }
465
+ }
466
+ return keys2;
467
+ };
468
+ const get2 = (key) => {
469
+ const resolvedKey = resolveKey(key);
470
+ const record = read(resolvedKey);
471
+ if (!record) return void 0;
472
+ if (isExpired(record)) {
473
+ removeResolved(resolvedKey);
474
+ return void 0;
475
+ }
476
+ return record.value;
477
+ };
478
+ const keys = () => getResolvedKeys().reduce((result, key) => {
479
+ const record = read(key);
480
+ if (!record || isExpired(record)) {
481
+ removeResolved(key);
482
+ return result;
483
+ }
484
+ result.push(unresolveKey(key));
485
+ return result;
486
+ }, []);
487
+ return {
488
+ set(key, value, setOptions = {}) {
489
+ write(resolveKey(key), {
490
+ value,
491
+ expiresAt: getExpiresAt(setOptions.ttl)
492
+ });
493
+ },
494
+ get: get2,
495
+ has(key) {
496
+ return get2(key) !== void 0;
497
+ },
498
+ remove(key) {
499
+ removeResolved(resolveKey(key));
500
+ },
501
+ clear() {
502
+ getResolvedKeys().forEach(removeResolved);
503
+ },
504
+ keys,
505
+ size() {
506
+ return keys().length;
507
+ }
508
+ };
509
+ }
510
+ var cache = createCache();
511
+ var { sm2, sm4 } = smCrypto;
512
+ function createCrypto(options = {}) {
513
+ return {
514
+ encrypt(value, secret) {
515
+ return encrypt(
516
+ value,
517
+ getRequiredKey(secret != null ? secret : options.aesKey, "AES key"),
518
+ options.aesOptions
519
+ );
520
+ },
521
+ decrypt(value, secret) {
522
+ return decrypt(
523
+ value,
524
+ getRequiredKey(secret != null ? secret : options.aesKey, "AES key"),
525
+ options.aesOptions
526
+ );
527
+ },
528
+ encryptAes(value, secret) {
529
+ return encryptAes(
530
+ value,
531
+ getRequiredKey(secret != null ? secret : options.aesKey, "AES key"),
532
+ options.aesOptions
533
+ );
534
+ },
535
+ decryptAes(value, secret) {
536
+ return decryptAes(
537
+ value,
538
+ getRequiredKey(secret != null ? secret : options.aesKey, "AES key"),
539
+ options.aesOptions
540
+ );
541
+ },
542
+ encryptRsa(value, publicKey) {
543
+ return encryptRsa(
544
+ value,
545
+ getRequiredKey(
546
+ publicKey != null ? publicKey : options.rsaPublicKey,
547
+ "RSA public key"
548
+ )
549
+ );
550
+ },
551
+ decryptRsa(value, privateKey) {
552
+ return decryptRsa(
553
+ value,
554
+ getRequiredKey(
555
+ privateKey != null ? privateKey : options.rsaPrivateKey,
556
+ "RSA private key"
557
+ )
558
+ );
559
+ },
560
+ encryptSm2(value, publicKey) {
561
+ return encryptSm2(
562
+ value,
563
+ getRequiredKey(
564
+ publicKey != null ? publicKey : options.sm2PublicKey,
565
+ "SM2 public key"
566
+ ),
567
+ options.sm2Options
568
+ );
569
+ },
570
+ decryptSm2(value, privateKey) {
571
+ return decryptSm2(
572
+ value,
573
+ getRequiredKey(
574
+ privateKey != null ? privateKey : options.sm2PrivateKey,
575
+ "SM2 private key"
576
+ ),
577
+ options.sm2Options
578
+ );
579
+ },
580
+ encryptSm4(value, key) {
581
+ return encryptSm4(
582
+ value,
583
+ getRequiredKey(key != null ? key : options.sm4Key, "SM4 key"),
584
+ options.sm4Options
585
+ );
586
+ },
587
+ decryptSm4(value, key) {
588
+ return decryptSm4(
589
+ value,
590
+ getRequiredKey(key != null ? key : options.sm4Key, "SM4 key"),
591
+ options.sm4Options
592
+ );
593
+ }
594
+ };
595
+ }
596
+ function encrypt(value, secret, options) {
597
+ return encryptAes(value, secret, options);
598
+ }
599
+ function decrypt(value, secret, options) {
600
+ return decryptAes(value, secret, options);
601
+ }
602
+ function encryptAes(value, secret, options) {
603
+ return CryptoJS.AES.encrypt(
604
+ value,
605
+ getAesKey(secret, options),
606
+ getAesOptions(options)
607
+ ).toString();
608
+ }
609
+ function decryptAes(value, secret, options) {
610
+ return CryptoJS.AES.decrypt(
611
+ value,
612
+ getAesKey(secret, options),
613
+ getAesOptions(options)
614
+ ).toString(CryptoJS.enc.Utf8);
615
+ }
616
+ function encryptRsa(value, publicKey) {
617
+ const rsa = createRsa({
618
+ publicKey
619
+ });
620
+ const encrypted = rsa.encryptLong(value);
621
+ if (!encrypted) {
622
+ throw new Error("RSA encrypt failed");
623
+ }
624
+ return encrypted;
625
+ }
626
+ function decryptRsa(value, privateKey) {
627
+ const rsa = createRsa({
628
+ privateKey
629
+ });
630
+ const decrypted = rsa.decryptLong(value);
631
+ if (!decrypted) {
632
+ throw new Error("RSA decrypt failed");
633
+ }
634
+ return decrypted;
635
+ }
636
+ function encryptSm2(value, publicKey, options = {}) {
637
+ var _a;
638
+ return sm2.doEncrypt(
639
+ value,
640
+ publicKey,
641
+ (_a = options.cipherMode) != null ? _a : 1
642
+ );
643
+ }
644
+ function decryptSm2(value, privateKey, options = {}) {
645
+ var _a;
646
+ return sm2.doDecrypt(
647
+ value,
648
+ privateKey,
649
+ (_a = options.cipherMode) != null ? _a : 1
650
+ );
651
+ }
652
+ function encryptSm4(value, key, options = {}) {
653
+ return sm4.encrypt(value, key, options);
654
+ }
655
+ function decryptSm4(value, key, options = {}) {
656
+ return sm4.decrypt(value, key, options);
657
+ }
658
+ function md5(value) {
659
+ return CryptoJS.MD5(value).toString();
660
+ }
661
+ function sha256(value) {
662
+ return CryptoJS.SHA256(value).toString();
663
+ }
664
+ function toBase64(value) {
665
+ return CryptoJS.enc.Base64.stringify(
666
+ CryptoJS.enc.Utf8.parse(value)
667
+ );
668
+ }
669
+ function fromBase64(value) {
670
+ return CryptoJS.enc.Base64.parse(value).toString(
671
+ CryptoJS.enc.Utf8
672
+ );
673
+ }
674
+ function getAesKey(secret, options) {
675
+ if ((options == null ? void 0 : options.keyMode) === "passphrase") {
676
+ return secret;
677
+ }
678
+ return CryptoJS.enc.Utf8.parse(secret);
679
+ }
680
+ function getAesOptions(options) {
681
+ var _a, _b;
682
+ if ((options == null ? void 0 : options.keyMode) === "passphrase") {
683
+ return {};
684
+ }
685
+ const aesOptions = {
686
+ mode: CryptoJS.mode[(_a = options == null ? void 0 : options.mode) != null ? _a : "ECB"],
687
+ padding: CryptoJS.pad[(_b = options == null ? void 0 : options.padding) != null ? _b : "Pkcs7"]
688
+ };
689
+ if (options == null ? void 0 : options.iv) {
690
+ aesOptions.iv = CryptoJS.enc.Utf8.parse(options.iv);
691
+ }
692
+ return aesOptions;
693
+ }
694
+ function createRsa(options) {
695
+ const EncryptLong = getEncryptLong();
696
+ const rsa = new EncryptLong();
697
+ if (options.publicKey) {
698
+ rsa.setPublicKey(options.publicKey);
699
+ }
700
+ if (options.privateKey) {
701
+ rsa.setPrivateKey(options.privateKey);
702
+ }
703
+ return rsa;
704
+ }
705
+ function getEncryptLong() {
706
+ if (typeof window === "undefined") {
707
+ throw new Error("RSA is only available in browser environments");
708
+ }
709
+ const requireFn = getRequire();
710
+ if (!requireFn) {
711
+ throw new Error("RSA is only available in CommonJS-compatible environments");
712
+ }
713
+ const module = requireFn("encryptlong");
714
+ return "default" in module ? module.default : module;
715
+ }
716
+ function getRequire() {
717
+ return typeof __require === "function" ? __require : void 0;
718
+ }
719
+ function getRequiredKey(key, name) {
720
+ if (!key) {
721
+ throw new Error(`${name} is required`);
722
+ }
723
+ return key;
724
+ }
725
+
726
+ // src/date/index.ts
727
+ function toDate(value) {
728
+ if (value instanceof Date) {
729
+ return new Date(value.getTime());
730
+ }
731
+ return new Date(value);
732
+ }
733
+ function isValidDate(value) {
734
+ return !Number.isNaN(toDate(value).getTime());
735
+ }
736
+ function formatDate(value, pattern = "YYYY-MM-DD HH:mm:ss") {
737
+ const date = toDate(value);
738
+ if (Number.isNaN(date.getTime())) return "";
739
+ const tokens = {
740
+ YYYY: String(date.getFullYear()),
741
+ YY: String(date.getFullYear()).slice(-2),
742
+ MM: pad(date.getMonth() + 1),
743
+ M: String(date.getMonth() + 1),
744
+ DD: pad(date.getDate()),
745
+ D: String(date.getDate()),
746
+ HH: pad(date.getHours()),
747
+ H: String(date.getHours()),
748
+ mm: pad(date.getMinutes()),
749
+ m: String(date.getMinutes()),
750
+ ss: pad(date.getSeconds()),
751
+ s: String(date.getSeconds()),
752
+ SSS: pad(date.getMilliseconds(), 3)
753
+ };
754
+ return pattern.replace(
755
+ /YYYY|YY|SSS|MM|M|DD|D|HH|H|mm|m|ss|s/g,
756
+ (token) => tokens[token]
757
+ );
758
+ }
759
+ function startOfDay(value) {
760
+ const date = toDate(value);
761
+ date.setHours(0, 0, 0, 0);
762
+ return date;
763
+ }
764
+ function endOfDay(value) {
765
+ const date = toDate(value);
766
+ date.setHours(23, 59, 59, 999);
767
+ return date;
768
+ }
769
+ function addDays(value, amount) {
770
+ const date = toDate(value);
771
+ date.setDate(date.getDate() + amount);
772
+ return date;
773
+ }
774
+ function diffDays(left, right) {
775
+ return Math.trunc(
776
+ (toDate(left).getTime() - toDate(right).getTime()) / 864e5
777
+ );
778
+ }
779
+ function diffHours(left, right) {
780
+ return Math.trunc(
781
+ (toDate(left).getTime() - toDate(right).getTime()) / 36e5
782
+ );
783
+ }
784
+ function fromNow(value, now = /* @__PURE__ */ new Date()) {
785
+ const diff = toDate(value).getTime() - toDate(now).getTime();
786
+ const absDiff = Math.abs(diff);
787
+ const suffix = diff >= 0 ? "\u540E" : "\u524D";
788
+ if (absDiff < 6e4) return "\u521A\u521A";
789
+ const units = [
790
+ ["\u5E74", 31536e6],
791
+ ["\u4E2A\u6708", 2592e6],
792
+ ["\u5929", 864e5],
793
+ ["\u5C0F\u65F6", 36e5],
794
+ ["\u5206\u949F", 6e4]
795
+ ];
796
+ const unit = units.find(([, size]) => absDiff >= size);
797
+ if (!unit) return "\u521A\u521A";
798
+ return `${Math.floor(absDiff / unit[1])}${unit[0]}${suffix}`;
799
+ }
800
+ function pad(value, length = 2) {
801
+ return String(value).padStart(length, "0");
802
+ }
803
+
804
+ // src/number/index.ts
805
+ function toFixedSafe(value, precision = 2) {
806
+ const scale = 10 ** precision;
807
+ const rounded = Math.round((value + Number.EPSILON) * scale) / scale;
808
+ return rounded.toFixed(precision);
809
+ }
810
+ function formatThousands(value, separator = ",") {
811
+ const [integer, decimal] = String(value).split(".");
812
+ const sign = integer.startsWith("-") ? "-" : "";
813
+ const normalized = sign ? integer.slice(1) : integer;
814
+ const formatted = normalized.replace(
815
+ /\B(?=(\d{3})+(?!\d))/g,
816
+ separator
817
+ );
818
+ return `${sign}${formatted}${decimal ? `.${decimal}` : ""}`;
819
+ }
820
+ function formatMoney(value, options = {}) {
821
+ const {
822
+ precision = 2,
823
+ symbol = "\xA5",
824
+ thousand = ",",
825
+ decimal = "."
826
+ } = options;
827
+ const fixed = toFixedSafe(value, precision);
828
+ const formatted = formatThousands(fixed, thousand);
829
+ return `${symbol}${formatted.replace(".", decimal)}`;
830
+ }
831
+ function formatPercent(value, options = {}) {
832
+ const {
833
+ precision = 2,
834
+ multiplier = 100
835
+ } = options;
836
+ return `${toFixedSafe(value * multiplier, precision)}%`;
837
+ }
838
+ function formatFileSize(bytes, precision = 2) {
839
+ if (!Number.isFinite(bytes)) return "";
840
+ if (bytes <= 0) return "0 B";
841
+ const units = ["B", "KB", "MB", "GB", "TB", "PB"];
842
+ const index = Math.min(
843
+ Math.floor(Math.log(bytes) / Math.log(1024)),
844
+ units.length - 1
845
+ );
846
+ const value = bytes / 1024 ** index;
847
+ return `${toFixedSafe(value, index === 0 ? 0 : precision)} ${units[index]}`;
848
+ }
849
+ function clamp(value, min, max) {
850
+ return Math.min(Math.max(value, min), max);
851
+ }
852
+
853
+ // src/tree/index.ts
854
+ var defaultTreeOptions = {
855
+ idKey: "id",
856
+ parentKey: "parentId",
857
+ childrenKey: "children"
858
+ };
859
+ function listToTree(list, options = {}) {
860
+ const config = getTreeOptions(options);
861
+ const nodeMap = /* @__PURE__ */ new Map();
862
+ const roots = [];
863
+ list.forEach((item) => {
864
+ nodeMap.set(item[config.idKey], {
865
+ ...item,
866
+ [config.childrenKey]: []
867
+ });
868
+ });
869
+ nodeMap.forEach((node) => {
870
+ const parentId = node[config.parentKey];
871
+ const parent = nodeMap.get(parentId);
872
+ if (parent) {
873
+ getChildren(parent, config.childrenKey).push(node);
874
+ return;
875
+ }
876
+ roots.push(node);
877
+ });
878
+ return roots;
879
+ }
880
+ function treeToList(tree, options = {}) {
881
+ const config = getTreeOptions(options);
882
+ const result = [];
883
+ walkTree(tree, (node) => {
884
+ const {
885
+ [config.childrenKey]: _children,
886
+ ...rest
887
+ } = node;
888
+ result.push(rest);
889
+ }, config.childrenKey);
890
+ return result;
891
+ }
892
+ function findTreeNode(tree, predicate, options = {}) {
893
+ const config = getTreeOptions(options);
894
+ for (const node of tree) {
895
+ if (predicate(node)) return node;
896
+ const found = findTreeNode(
897
+ getChildren(node, config.childrenKey),
898
+ predicate,
899
+ config
900
+ );
901
+ if (found) return found;
902
+ }
903
+ return void 0;
904
+ }
905
+ function filterTree(tree, predicate, options = {}) {
906
+ const config = getTreeOptions(options);
907
+ return tree.reduce((result, node) => {
908
+ const children = filterTree(
909
+ getChildren(node, config.childrenKey),
910
+ predicate,
911
+ config
912
+ );
913
+ if (predicate(node) || children.length > 0) {
914
+ result.push({
915
+ ...node,
916
+ [config.childrenKey]: children
917
+ });
918
+ }
919
+ return result;
920
+ }, []);
921
+ }
922
+ function getTreePath(tree, predicate, options = {}) {
923
+ const config = getTreeOptions(options);
924
+ for (const node of tree) {
925
+ if (predicate(node)) return [node];
926
+ const childPath = getTreePath(
927
+ getChildren(node, config.childrenKey),
928
+ predicate,
929
+ config
930
+ );
931
+ if (childPath.length > 0) {
932
+ return [node, ...childPath];
933
+ }
934
+ }
935
+ return [];
936
+ }
937
+ function getTreeLeaves(tree, options = {}) {
938
+ const config = getTreeOptions(options);
939
+ const leaves = [];
940
+ walkTree(tree, (node) => {
941
+ if (getChildren(node, config.childrenKey).length === 0) {
942
+ leaves.push(node);
943
+ }
944
+ }, config.childrenKey);
945
+ return leaves;
946
+ }
947
+ function walkTree(tree, visitor, childrenKey) {
948
+ tree.forEach((node) => {
949
+ visitor(node);
950
+ walkTree(
951
+ getChildren(node, childrenKey),
952
+ visitor,
953
+ childrenKey
954
+ );
955
+ });
956
+ }
957
+ function getChildren(node, childrenKey) {
958
+ const children = node[childrenKey];
959
+ return Array.isArray(children) ? children : [];
960
+ }
961
+ function getTreeOptions(options) {
962
+ return {
963
+ ...defaultTreeOptions,
964
+ ...options
965
+ };
966
+ }
967
+
968
+ // src/storage/index.ts
969
+ var defaultNamespace = "szkj:storage:";
970
+ function createStorage(options = {}) {
971
+ var _a, _b;
972
+ const namespace = (_a = options.namespace) != null ? _a : defaultNamespace;
973
+ const storage = (_b = options.storage) != null ? _b : getDefaultStorage("localStorage");
974
+ const resolveKey = (key) => `${namespace}${key}`;
975
+ const unresolveKey = (key) => key.startsWith(namespace) ? key.slice(namespace.length) : key;
976
+ const getExpiresAt = (ttl = options.ttl) => {
977
+ if (typeof ttl !== "number") return null;
978
+ return Date.now() + Math.max(0, ttl);
979
+ };
980
+ const encode = (value) => options.encrypt ? options.encrypt(value) : value;
981
+ const decode = (value) => options.decrypt ? options.decrypt(value) : value;
982
+ const readRecord = (resolvedKey) => {
983
+ const raw = storage.getItem(resolvedKey);
984
+ if (!raw) return void 0;
985
+ try {
986
+ return JSON.parse(decode(raw));
987
+ } catch {
988
+ storage.removeItem(resolvedKey);
989
+ return void 0;
990
+ }
991
+ };
992
+ const removeResolved = (resolvedKey) => {
993
+ storage.removeItem(resolvedKey);
994
+ };
995
+ const isExpired = (record) => typeof record.expiresAt === "number" && record.expiresAt <= Date.now();
996
+ const getResolvedKeys = () => {
997
+ const keys2 = [];
998
+ for (let index = 0; index < storage.length; index += 1) {
999
+ const key = storage.key(index);
1000
+ if (key == null ? void 0 : key.startsWith(namespace)) {
1001
+ keys2.push(key);
1002
+ }
1003
+ }
1004
+ return keys2;
1005
+ };
1006
+ const get2 = (key) => {
1007
+ const resolvedKey = resolveKey(key);
1008
+ const record = readRecord(resolvedKey);
1009
+ if (!record) return void 0;
1010
+ if (isExpired(record)) {
1011
+ removeResolved(resolvedKey);
1012
+ return void 0;
1013
+ }
1014
+ return record.value;
1015
+ };
1016
+ const keys = () => getResolvedKeys().reduce((result, key) => {
1017
+ const record = readRecord(key);
1018
+ if (!record || isExpired(record)) {
1019
+ removeResolved(key);
1020
+ return result;
1021
+ }
1022
+ result.push(unresolveKey(key));
1023
+ return result;
1024
+ }, []);
1025
+ return {
1026
+ set(key, value, setOptions = {}) {
1027
+ const record = {
1028
+ value,
1029
+ expiresAt: getExpiresAt(setOptions.ttl)
1030
+ };
1031
+ storage.setItem(
1032
+ resolveKey(key),
1033
+ encode(JSON.stringify(record))
1034
+ );
1035
+ },
1036
+ get: get2,
1037
+ getRaw(key) {
1038
+ const raw = storage.getItem(resolveKey(key));
1039
+ if (!raw) return void 0;
1040
+ return decode(raw);
1041
+ },
1042
+ has(key) {
1043
+ return get2(key) !== void 0;
1044
+ },
1045
+ remove(key) {
1046
+ removeResolved(resolveKey(key));
1047
+ },
1048
+ clear() {
1049
+ getResolvedKeys().forEach(removeResolved);
1050
+ },
1051
+ keys,
1052
+ size() {
1053
+ return keys().length;
1054
+ }
1055
+ };
1056
+ }
1057
+ var localStore = createStorage({
1058
+ storage: getDefaultStorage("localStorage")
1059
+ });
1060
+ var sessionStore = createStorage({
1061
+ namespace: "szkj:session:",
1062
+ storage: getDefaultStorage("sessionStorage")
1063
+ });
1064
+ function getDefaultStorage(type) {
1065
+ if (typeof globalThis !== "undefined" && type in globalThis) {
1066
+ const storage = globalThis[type];
1067
+ if (storage) return storage;
1068
+ }
1069
+ return createMemoryStorage();
1070
+ }
1071
+ function createMemoryStorage() {
1072
+ const store = /* @__PURE__ */ new Map();
1073
+ return {
1074
+ get length() {
1075
+ return store.size;
1076
+ },
1077
+ key(index) {
1078
+ var _a;
1079
+ return (_a = Array.from(store.keys())[index]) != null ? _a : null;
1080
+ },
1081
+ getItem(key) {
1082
+ var _a;
1083
+ return (_a = store.get(key)) != null ? _a : null;
1084
+ },
1085
+ setItem(key, value) {
1086
+ store.set(key, value);
1087
+ },
1088
+ removeItem(key) {
1089
+ store.delete(key);
1090
+ },
1091
+ clear() {
1092
+ store.clear();
1093
+ }
1094
+ };
1095
+ }
1096
+
1097
+ // src/copy/index.ts
1098
+ async function copyText(text, options) {
1099
+ var _a, _b;
1100
+ if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
1101
+ try {
1102
+ await navigator.clipboard.writeText(text);
1103
+ (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
1104
+ return true;
1105
+ } catch (error) {
1106
+ (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(options, error);
1107
+ return false;
1108
+ }
1109
+ }
1110
+ return fallbackCopyText(text, options);
1111
+ }
1112
+ function fallbackCopyText(text, options) {
1113
+ var _a, _b, _c;
1114
+ const textarea = document.createElement("textarea");
1115
+ textarea.value = text;
1116
+ textarea.style.position = "fixed";
1117
+ textarea.style.top = "-9999px";
1118
+ textarea.style.left = "-9999px";
1119
+ textarea.style.opacity = "0";
1120
+ textarea.setAttribute("readonly", "");
1121
+ textarea.setAttribute("aria-hidden", "true");
1122
+ document.body.appendChild(textarea);
1123
+ textarea.focus();
1124
+ textarea.select();
1125
+ let success = false;
1126
+ try {
1127
+ success = document.execCommand("copy");
1128
+ if (success) {
1129
+ (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
1130
+ } else {
1131
+ (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(options, new Error('execCommand("copy") returned false'));
1132
+ }
1133
+ } catch (error) {
1134
+ (_c = options == null ? void 0 : options.onError) == null ? void 0 : _c.call(options, error);
1135
+ } finally {
1136
+ document.body.removeChild(textarea);
1137
+ }
1138
+ return success;
1139
+ }
1140
+
1141
+ // src/download/index.ts
1142
+ function downloadBlob(blob, options = {}) {
1143
+ const { filename = "download", mimeType } = options;
1144
+ const downloadBlob2 = mimeType ? new Blob([blob], { type: mimeType }) : blob;
1145
+ const url = URL.createObjectURL(downloadBlob2);
1146
+ triggerDownload(url, filename);
1147
+ URL.revokeObjectURL(url);
1148
+ }
1149
+ function downloadText(text, filename = "download.txt") {
1150
+ const blob = new Blob([text], { type: "text/plain;charset=utf-8" });
1151
+ downloadBlob(blob, { filename });
1152
+ }
1153
+ function downloadJSON(data, filename = "download.json") {
1154
+ const text = JSON.stringify(data, null, 2);
1155
+ const blob = new Blob([text], { type: "application/json;charset=utf-8" });
1156
+ downloadBlob(blob, { filename });
1157
+ }
1158
+ async function downloadStream(response, options = {}) {
1159
+ var _a;
1160
+ const { filename = "download", onProgress, onError } = options;
1161
+ try {
1162
+ const contentLength = response.headers.get("content-length");
1163
+ const total = contentLength ? parseInt(contentLength, 10) : 0;
1164
+ const reader = (_a = response.body) == null ? void 0 : _a.getReader();
1165
+ if (!reader) {
1166
+ throw new Error("Response body is not readable");
1167
+ }
1168
+ const chunks = [];
1169
+ let loaded = 0;
1170
+ while (true) {
1171
+ const { done, value } = await reader.read();
1172
+ if (done) break;
1173
+ chunks.push(value);
1174
+ loaded += value.length;
1175
+ onProgress == null ? void 0 : onProgress(loaded, total);
1176
+ }
1177
+ const blob = new Blob(chunks);
1178
+ downloadBlob(blob, { filename });
1179
+ } catch (error) {
1180
+ onError == null ? void 0 : onError(error);
1181
+ throw error;
1182
+ }
1183
+ }
1184
+ function triggerDownload(url, filename) {
1185
+ const link = document.createElement("a");
1186
+ link.href = url;
1187
+ link.download = filename;
1188
+ link.style.display = "none";
1189
+ document.body.appendChild(link);
1190
+ link.click();
1191
+ document.body.removeChild(link);
1192
+ }
1193
+
1194
+ // src/file/index.ts
1195
+ function fileToBase64(file) {
1196
+ return new Promise((resolve, reject) => {
1197
+ const reader = new FileReader();
1198
+ reader.onload = () => {
1199
+ var _a;
1200
+ const result = reader.result;
1201
+ const base64 = (_a = result.split(",")[1]) != null ? _a : result;
1202
+ resolve(base64);
1203
+ };
1204
+ reader.onerror = reject;
1205
+ reader.readAsDataURL(file);
1206
+ });
1207
+ }
1208
+ function base64ToBlob(base64, mimeType = "application/octet-stream") {
1209
+ const byteCharacters = atob(base64);
1210
+ const byteNumbers = new Array(byteCharacters.length);
1211
+ for (let i = 0; i < byteCharacters.length; i++) {
1212
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
1213
+ }
1214
+ const byteArray = new Uint8Array(byteNumbers);
1215
+ return new Blob([byteArray], { type: mimeType });
1216
+ }
1217
+ function getFileExtension(filename) {
1218
+ const lastDot = filename.lastIndexOf(".");
1219
+ return lastDot === -1 ? "" : filename.slice(lastDot + 1).toLowerCase();
1220
+ }
1221
+
1222
+ // src/object/index.ts
1223
+ function deepClone(obj) {
1224
+ if (obj === null || typeof obj !== "object") {
1225
+ return obj;
1226
+ }
1227
+ if (obj instanceof Date) {
1228
+ return new Date(obj.getTime());
1229
+ }
1230
+ if (obj instanceof Array) {
1231
+ return obj.map((item) => deepClone(item));
1232
+ }
1233
+ if (obj instanceof Object) {
1234
+ const cloned = {};
1235
+ Object.keys(obj).forEach((key) => {
1236
+ cloned[key] = deepClone(obj[key]);
1237
+ });
1238
+ return cloned;
1239
+ }
1240
+ throw new Error("Unable to copy object");
1241
+ }
1242
+ function deepMerge(target, ...sources) {
1243
+ if (!sources.length) return target;
1244
+ const source = sources.shift();
1245
+ if (!source) return target;
1246
+ for (const key in source) {
1247
+ if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
1248
+ if (!target[key] || typeof target[key] !== "object") {
1249
+ target[key] = {};
1250
+ }
1251
+ deepMerge(
1252
+ target[key],
1253
+ source[key]
1254
+ );
1255
+ } else {
1256
+ target[key] = source[key];
1257
+ }
1258
+ }
1259
+ return deepMerge(target, ...sources);
1260
+ }
1261
+ function removeEmptyValues(obj, options = {}) {
1262
+ const {
1263
+ removeNull = true,
1264
+ removeUndefined = true,
1265
+ removeEmptyString = false,
1266
+ removeEmptyArray = false,
1267
+ removeEmptyObject = false
1268
+ } = options;
1269
+ const result = {};
1270
+ for (const key in obj) {
1271
+ const value = obj[key];
1272
+ if (removeUndefined && value === void 0) continue;
1273
+ if (removeNull && value === null) continue;
1274
+ if (removeEmptyString && value === "") continue;
1275
+ if (removeEmptyArray && Array.isArray(value) && value.length === 0) continue;
1276
+ if (removeEmptyObject && typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0) continue;
1277
+ result[key] = value;
1278
+ }
1279
+ return result;
1280
+ }
1281
+ function pick(obj, keys) {
1282
+ const result = {};
1283
+ keys.forEach((key) => {
1284
+ if (key in obj) {
1285
+ result[key] = obj[key];
1286
+ }
1287
+ });
1288
+ return result;
1289
+ }
1290
+ function omit(obj, keys) {
1291
+ const result = { ...obj };
1292
+ keys.forEach((key) => {
1293
+ delete result[key];
1294
+ });
1295
+ return result;
1296
+ }
1297
+ function flatten(obj, prefix = "", result = {}) {
1298
+ for (const key in obj) {
1299
+ const newKey = prefix ? `${prefix}.${key}` : key;
1300
+ const value = obj[key];
1301
+ if (value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date)) {
1302
+ flatten(value, newKey, result);
1303
+ } else {
1304
+ result[newKey] = value;
1305
+ }
1306
+ }
1307
+ return result;
1308
+ }
1309
+ function unflatten(obj) {
1310
+ const result = {};
1311
+ for (const key in obj) {
1312
+ const keys = key.split(".");
1313
+ let current = result;
1314
+ for (let i = 0; i < keys.length - 1; i++) {
1315
+ const k = keys[i];
1316
+ if (!(k in current)) {
1317
+ current[k] = {};
1318
+ }
1319
+ current = current[k];
1320
+ }
1321
+ current[keys[keys.length - 1]] = obj[key];
1322
+ }
1323
+ return result;
1324
+ }
1325
+
1326
+ // src/array/index.ts
1327
+ function flattenArray(arr, depth = Infinity) {
1328
+ const result = [];
1329
+ for (const item of arr) {
1330
+ if (Array.isArray(item) && depth > 0) {
1331
+ result.push(...flattenArray(item, depth - 1));
1332
+ } else {
1333
+ result.push(item);
1334
+ }
1335
+ }
1336
+ return result;
1337
+ }
1338
+ function chunk(arr, size) {
1339
+ if (size <= 0) return [];
1340
+ const result = [];
1341
+ for (let i = 0; i < arr.length; i += size) {
1342
+ result.push(arr.slice(i, i + size));
1343
+ }
1344
+ return result;
1345
+ }
1346
+ function unique(arr) {
1347
+ return [...new Set(arr)];
1348
+ }
1349
+ function uniqueBy(arr, key) {
1350
+ const seen = /* @__PURE__ */ new Set();
1351
+ return arr.filter((item) => {
1352
+ const value = typeof key === "function" ? key(item) : item[key];
1353
+ if (seen.has(value)) return false;
1354
+ seen.add(value);
1355
+ return true;
1356
+ });
1357
+ }
1358
+ function groupBy(arr, key) {
1359
+ const result = {};
1360
+ arr.forEach((item) => {
1361
+ const value = typeof key === "function" ? key(item) : item[key];
1362
+ const groupKey = String(value);
1363
+ if (!result[groupKey]) {
1364
+ result[groupKey] = [];
1365
+ }
1366
+ result[groupKey].push(item);
1367
+ });
1368
+ return result;
1369
+ }
1370
+ function intersection(arr1, arr2) {
1371
+ const set2 = new Set(arr2);
1372
+ return [...new Set(arr1)].filter((item) => set2.has(item));
1373
+ }
1374
+ function difference(arr1, arr2) {
1375
+ const set2 = new Set(arr2);
1376
+ return [...new Set(arr1)].filter((item) => !set2.has(item));
1377
+ }
1378
+ function shuffle(arr) {
1379
+ const result = [...arr];
1380
+ for (let i = result.length - 1; i > 0; i--) {
1381
+ const j = Math.floor(Math.random() * (i + 1));
1382
+ [result[i], result[j]] = [result[j], result[i]];
1383
+ }
1384
+ return result;
1385
+ }
1386
+ function sortBy(arr, key, order = "asc") {
1387
+ const result = [...arr];
1388
+ return result.sort((a, b) => {
1389
+ const valueA = typeof key === "function" ? key(a) : a[key];
1390
+ const valueB = typeof key === "function" ? key(b) : b[key];
1391
+ if (valueA === valueB) return 0;
1392
+ if (valueA == null) return order === "asc" ? -1 : 1;
1393
+ if (valueB == null) return order === "asc" ? 1 : -1;
1394
+ if (typeof valueA === "string" && typeof valueB === "string") {
1395
+ const comparison = valueA.localeCompare(valueB);
1396
+ return order === "asc" ? comparison : -comparison;
1397
+ }
1398
+ const numA = typeof valueA === "number" ? valueA : 0;
1399
+ const numB = typeof valueB === "number" ? valueB : 0;
1400
+ if (numA < numB) return order === "asc" ? -1 : 1;
1401
+ if (numA > numB) return order === "asc" ? 1 : -1;
1402
+ return 0;
1403
+ });
1404
+ }
1405
+ function sum(arr) {
1406
+ return arr.reduce((acc, val) => acc + val, 0);
1407
+ }
1408
+ function average(arr) {
1409
+ if (arr.length === 0) return 0;
1410
+ return sum(arr) / arr.length;
1411
+ }
1412
+ function maxBy(arr, key) {
1413
+ if (arr.length === 0) return void 0;
1414
+ return arr.reduce((max, item) => {
1415
+ const value = typeof key === "function" ? key(item) : item[key];
1416
+ const maxValue = typeof key === "function" ? key(max) : max[key];
1417
+ return value > maxValue ? item : max;
1418
+ });
1419
+ }
1420
+ function minBy(arr, key) {
1421
+ if (arr.length === 0) return void 0;
1422
+ return arr.reduce((min, item) => {
1423
+ const value = typeof key === "function" ? key(item) : item[key];
1424
+ const minValue = typeof key === "function" ? key(min) : min[key];
1425
+ return value < minValue ? item : min;
1426
+ });
1427
+ }
1428
+ function moveItem(arr, fromIndex, toIndex) {
1429
+ if (fromIndex < 0 || fromIndex >= arr.length || toIndex < 0 || toIndex >= arr.length || fromIndex === toIndex) {
1430
+ return [...arr];
1431
+ }
1432
+ const result = [...arr];
1433
+ const [removed] = result.splice(fromIndex, 1);
1434
+ result.splice(toIndex, 0, removed);
1435
+ return result;
1436
+ }
1437
+ function swapItems(arr, index1, index2) {
1438
+ if (index1 < 0 || index1 >= arr.length || index2 < 0 || index2 >= arr.length || index1 === index2) {
1439
+ return [...arr];
1440
+ }
1441
+ const result = [...arr];
1442
+ [result[index1], result[index2]] = [result[index2], result[index1]];
1443
+ return result;
1444
+ }
1445
+
1446
+ // src/string/index.ts
1447
+ function isEmpty(str) {
1448
+ if (str === null || str === void 0) return true;
1449
+ if (typeof str !== "string") return false;
1450
+ return str.trim().length === 0;
1451
+ }
1452
+ function isNotEmpty(str) {
1453
+ return !isEmpty(str);
1454
+ }
1455
+ function capitalize(str) {
1456
+ if (!str) return str;
1457
+ return str.charAt(0).toUpperCase() + str.slice(1);
1458
+ }
1459
+ function uncapitalize(str) {
1460
+ if (!str) return str;
1461
+ return str.charAt(0).toLowerCase() + str.slice(1);
1462
+ }
1463
+ function camelCase(str) {
1464
+ return str.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^[A-Z]/, (char) => char.toLowerCase());
1465
+ }
1466
+ function pascalCase(str) {
1467
+ const camel = camelCase(str);
1468
+ return capitalize(camel);
1469
+ }
1470
+ function kebabCase(str) {
1471
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
1472
+ }
1473
+ function snakeCase(str) {
1474
+ return str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s\-]+/g, "_").toLowerCase();
1475
+ }
1476
+ function truncate(str, maxLength, suffix = "...") {
1477
+ if (str.length <= maxLength) return str;
1478
+ return str.slice(0, maxLength - suffix.length) + suffix;
1479
+ }
1480
+ function generateUUID() {
1481
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
1482
+ const random = Math.random() * 16 | 0;
1483
+ const value = char === "x" ? random : random & 3 | 8;
1484
+ return value.toString(16);
1485
+ });
1486
+ }
1487
+ function escapeHtml(str) {
1488
+ const htmlEscapes = {
1489
+ "&": "&amp;",
1490
+ "<": "&lt;",
1491
+ ">": "&gt;",
1492
+ '"': "&quot;",
1493
+ "'": "&#39;"
1494
+ };
1495
+ return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
1496
+ }
1497
+ function unescapeHtml(str) {
1498
+ const htmlUnescapes = {
1499
+ "&amp;": "&",
1500
+ "&lt;": "<",
1501
+ "&gt;": ">",
1502
+ "&quot;": '"',
1503
+ "&#39;": "'"
1504
+ };
1505
+ return str.replace(/&(?:amp|lt|gt|quot|#39);/g, (entity) => htmlUnescapes[entity]);
1506
+ }
1507
+ function parseQueryString(url) {
1508
+ const queryString = url.includes("?") ? url.split("?")[1] : url;
1509
+ const params = new URLSearchParams(queryString);
1510
+ const result = {};
1511
+ params.forEach((value, key) => {
1512
+ result[key] = value;
1513
+ });
1514
+ return result;
1515
+ }
1516
+ function stringifyQueryString(params) {
1517
+ const searchParams = new URLSearchParams();
1518
+ Object.entries(params).forEach(([key, value]) => {
1519
+ if (value !== void 0 && value !== null) {
1520
+ searchParams.append(key, String(value));
1521
+ }
1522
+ });
1523
+ const queryString = searchParams.toString();
1524
+ return queryString ? `?${queryString}` : "";
1525
+ }
1526
+ function buildUrl(baseUrl, params) {
1527
+ const queryString = stringifyQueryString(params);
1528
+ baseUrl.includes("?") ? "&" : queryString.replace("?", "?");
1529
+ return baseUrl + (baseUrl.includes("?") ? queryString.replace("?", "&") : queryString);
1530
+ }
1531
+
1532
+ // src/function/index.ts
1533
+ function debounce(func, options = {}) {
1534
+ const {
1535
+ wait = 0,
1536
+ leading = false,
1537
+ trailing = true
1538
+ } = options;
1539
+ let timer = null;
1540
+ let lastArgs = null;
1541
+ let lastThis = null;
1542
+ let result;
1543
+ function invokeFunc() {
1544
+ const args = lastArgs;
1545
+ const thisArg = lastThis;
1546
+ lastArgs = null;
1547
+ lastThis = null;
1548
+ result = func.apply(thisArg, args);
1549
+ return result;
1550
+ }
1551
+ function debounced(...args) {
1552
+ const shouldCallLeading = leading && timer === null;
1553
+ lastArgs = args;
1554
+ lastThis = this;
1555
+ if (timer !== null) {
1556
+ clearTimeout(timer);
1557
+ }
1558
+ if (shouldCallLeading) {
1559
+ invokeFunc();
1560
+ }
1561
+ timer = setTimeout(() => {
1562
+ timer = null;
1563
+ if (trailing && lastArgs) {
1564
+ invokeFunc();
1565
+ return;
1566
+ }
1567
+ lastArgs = null;
1568
+ lastThis = null;
1569
+ }, wait);
1570
+ return result;
1571
+ }
1572
+ debounced.cancel = function() {
1573
+ if (timer !== null) {
1574
+ clearTimeout(timer);
1575
+ }
1576
+ lastArgs = null;
1577
+ lastThis = null;
1578
+ timer = null;
1579
+ };
1580
+ debounced.flush = function() {
1581
+ if (timer === null) {
1582
+ return result;
1583
+ }
1584
+ clearTimeout(timer);
1585
+ timer = null;
1586
+ if (trailing && lastArgs) {
1587
+ return invokeFunc();
1588
+ }
1589
+ lastArgs = null;
1590
+ lastThis = null;
1591
+ return result;
1592
+ };
1593
+ debounced.pending = function() {
1594
+ return timer !== null;
1595
+ };
1596
+ return debounced;
1597
+ }
1598
+ function throttle(func, options = {}) {
1599
+ const {
1600
+ wait = 0,
1601
+ leading = true,
1602
+ trailing = true
1603
+ } = options;
1604
+ let timer = null;
1605
+ let lastArgs = null;
1606
+ let lastThis = null;
1607
+ let lastInvokeTime = null;
1608
+ let result;
1609
+ function invokeFunc(time) {
1610
+ const args = lastArgs;
1611
+ const thisArg = lastThis;
1612
+ lastArgs = null;
1613
+ lastThis = null;
1614
+ lastInvokeTime = time;
1615
+ result = func.apply(thisArg, args);
1616
+ return result;
1617
+ }
1618
+ function remainingWait(time) {
1619
+ const timeSinceLastInvoke = time - (lastInvokeTime != null ? lastInvokeTime : 0);
1620
+ return wait - timeSinceLastInvoke;
1621
+ }
1622
+ function startTimer(delay) {
1623
+ timer = setTimeout(() => {
1624
+ timer = null;
1625
+ if (trailing && lastArgs) {
1626
+ invokeFunc(Date.now());
1627
+ return;
1628
+ }
1629
+ lastArgs = null;
1630
+ lastThis = null;
1631
+ }, delay);
1632
+ }
1633
+ function throttled(...args) {
1634
+ const time = Date.now();
1635
+ lastArgs = args;
1636
+ lastThis = this;
1637
+ if (lastInvokeTime === null) {
1638
+ if (leading) {
1639
+ return invokeFunc(time);
1640
+ }
1641
+ lastInvokeTime = time;
1642
+ }
1643
+ const waitRemaining = remainingWait(time);
1644
+ if (waitRemaining <= 0) {
1645
+ if (timer !== null) {
1646
+ clearTimeout(timer);
1647
+ timer = null;
1648
+ }
1649
+ return invokeFunc(time);
1650
+ }
1651
+ if (timer === null && trailing) {
1652
+ startTimer(waitRemaining);
1653
+ }
1654
+ return result;
1655
+ }
1656
+ throttled.cancel = function() {
1657
+ if (timer !== null) {
1658
+ clearTimeout(timer);
1659
+ }
1660
+ lastArgs = null;
1661
+ lastThis = null;
1662
+ lastInvokeTime = null;
1663
+ timer = null;
1664
+ };
1665
+ throttled.flush = function() {
1666
+ if (timer === null) {
1667
+ return result;
1668
+ }
1669
+ clearTimeout(timer);
1670
+ timer = null;
1671
+ if (lastArgs) {
1672
+ return invokeFunc(Date.now());
1673
+ }
1674
+ return result;
1675
+ };
1676
+ throttled.pending = function() {
1677
+ return timer !== null;
1678
+ };
1679
+ return throttled;
1680
+ }
1681
+
1682
+ // src/get/index.ts
1683
+ function get(obj, path, defaultValue) {
1684
+ if (obj == null) return defaultValue;
1685
+ const keys = Array.isArray(path) ? path : path.split(".");
1686
+ let result = obj;
1687
+ for (const key of keys) {
1688
+ if (result == null) {
1689
+ return defaultValue;
1690
+ }
1691
+ result = result[key];
1692
+ }
1693
+ return result !== void 0 ? result : defaultValue;
1694
+ }
1695
+
1696
+ export { REGEXP_AMOUNT, REGEXP_BANK_CARD, REGEXP_CAR_PLATE, REGEXP_CHINESE, REGEXP_DECIMAL, REGEXP_EMAIL, REGEXP_FIXED_PHONE, REGEXP_ID_CARD, REGEXP_INTEGER, REGEXP_IPV4, REGEXP_IPV6, REGEXP_PASSPORT, REGEXP_PASSWORD, REGEXP_PHONE, REGEXP_PORT, REGEXP_POSITIVE_INTEGER, REGEXP_POSTAL_CODE, REGEXP_QQ, REGEXP_STRONG_PASSWORD, REGEXP_URL, REGEXP_USERNAME, addDays, average, base64ToBlob, buildUrl, cache, camelCase, capitalize, chunk, clamp, copyText, createCache, createCrypto, createStorage, debounce, decrypt, decryptAes, decryptRsa, decryptSm2, decryptSm4, deepClone, deepMerge, diffDays, diffHours, difference, downloadBlob, downloadJSON, downloadStream, downloadText, encrypt, encryptAes, encryptRsa, encryptSm2, encryptSm4, endOfDay, escapeHtml, fileToBase64, filterTree, findTreeNode, flatten, flattenArray, formatDate, formatFileSize, formatMoney, formatPercent, formatThousands, fromBase64, fromNow, generateUUID, get, getFileExtension, getTreeLeaves, getTreePath, groupBy, intersection, isAmount, isBankCard, isCarPlate, isChinese, isDecimal, isEmail, isEmpty, isFixedPhone, isIdCard, isInteger, isIpv4, isIpv6, isNotEmpty, isPassport, isPassword, isPhone, isPort, isPositiveInteger, isPostalCode, isQq, isStrongPassword, isUrl, isUsername, isValidDate, kebabCase, listToTree, localStore, mask, maskAccount, maskAddress, maskBankCard, maskCarPlate, maskEmail, maskFixedPhone, maskIdCard, maskIp, maskName, maskPassport, maskPhone, maskSecret, maxBy, md5, minBy, moveItem, omit, parseQueryString, pascalCase, pick, regexp, removeEmptyValues, sessionStore, sha256, shuffle, snakeCase, sortBy, startOfDay, stringifyQueryString, sum, swapItems, testRegexp, throttle, toBase64, toDate, toFixedSafe, treeToList, truncate, uncapitalize, unescapeHtml, unflatten, unique, uniqueBy };
1697
+ //# sourceMappingURL=index.js.map
1698
+ //# sourceMappingURL=index.js.map