tools-min-ns 1.14.3 → 1.16.2

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.
Files changed (40) hide show
  1. package/README.md +24 -2
  2. package/esm/array/ArrayUtil.d.ts +11 -0
  3. package/esm/array/ArrayUtil.js +27 -0
  4. package/esm/array/TreeUtil.js +9 -9
  5. package/esm/browser/fingerprint.js +12 -12
  6. package/esm/date/DateUtil.d.ts +8 -0
  7. package/esm/date/DateUtil.js +42 -1
  8. package/esm/func/FunctionUtil.d.ts +18 -18
  9. package/esm/func/FunctionUtil.js +18 -18
  10. package/esm/number/NumberUtil.d.ts +2 -1
  11. package/esm/number/NumberUtil.js +6 -2
  12. package/esm/pwd/PasswordUtil.d.ts +28 -0
  13. package/esm/pwd/PasswordUtil.js +90 -3
  14. package/esm/pwd/crypto.d.ts +6 -6
  15. package/esm/pwd/crypto.js +3 -3
  16. package/esm/pwd/lz-string.d.ts +15 -0
  17. package/esm/pwd/lz-string.js +486 -0
  18. package/esm/request/nsPromiseFn.js +3 -3
  19. package/esm/transfer/MapTransferUtil.d.ts +14 -0
  20. package/esm/transfer/MapTransferUtil.js +37 -0
  21. package/lib/array/ArrayUtil.d.ts +11 -0
  22. package/lib/array/ArrayUtil.js +27 -0
  23. package/lib/array/TreeUtil.js +9 -9
  24. package/lib/browser/fingerprint.js +12 -12
  25. package/lib/date/DateUtil.d.ts +8 -0
  26. package/lib/date/DateUtil.js +42 -1
  27. package/lib/func/FunctionUtil.d.ts +18 -18
  28. package/lib/func/FunctionUtil.js +17 -17
  29. package/lib/number/NumberUtil.d.ts +2 -1
  30. package/lib/number/NumberUtil.js +6 -2
  31. package/lib/pwd/PasswordUtil.d.ts +28 -0
  32. package/lib/pwd/PasswordUtil.js +100 -13
  33. package/lib/pwd/crypto.d.ts +6 -6
  34. package/lib/pwd/crypto.js +3 -3
  35. package/lib/pwd/lz-string.d.ts +15 -0
  36. package/lib/pwd/lz-string.js +491 -0
  37. package/lib/request/nsPromiseFn.js +3 -3
  38. package/lib/transfer/MapTransferUtil.d.ts +14 -0
  39. package/lib/transfer/MapTransferUtil.js +37 -0
  40. package/package.json +3 -4
package/README.md CHANGED
@@ -1,12 +1,34 @@
1
1
  # use tools-min-ns
2
2
 
3
3
  ```
4
- cnpm i tools-min-ns --save
4
+ pnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.16.2
9
+ > PasswordUtil
10
+ 新增minEncryptData/minDecryptData
8
11
 
9
- ## v1.14.2
12
+ ## v1.16.1
13
+ > MapTransferUtil
14
+ 4326/3857转换
15
+
16
+ ## v1.16.0
17
+ > PasswordUtil
18
+ 新增xor加解密
19
+
20
+ ## v1.15.3
21
+ > DateUtil.formatDateToFriendly3
22
+
23
+ ## v1.15.2
24
+ > NumberUtil.number2percentage 加入参数m
25
+
26
+ ## v1.15.1
27
+ > DateUtil formatDate 修复星期w和季度q
28
+
29
+ ## v1.14.4
30
+ > ArrayUtil repeatArray 创建一个数组,其中包含原数组的元素,重复一定次数
31
+ ## v1.14.3
10
32
  > StringUtil getUuiD 重构随机ID效率更高
11
33
  ## v1.14.2
12
34
  > DateUtil 日期格式化兼容优化
@@ -173,5 +173,16 @@ const chunkedArray = chunkArray(data, 3);
173
173
  console.log(chunkedArray);// [Array(3), Array(3), Array(3)]
174
174
  */
175
175
  function chunkArray<T>(array: T[], size: number): T[][];
176
+ /**
177
+ * 创建一个数组,其中包含原数组的元素,重复一定次数
178
+ * @param originalList [1, 2, 3]
179
+ * @param length 20
180
+ * @returns [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]
181
+ * @example
182
+ * const list = [1, 2, 3];
183
+ * const length = 20;
184
+ * console.log(repeatArray(list, length)); // 输出: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]
185
+ */
186
+ function repeatArray<T>(originalList: T[], length: number): T[];
176
187
  }
177
188
  export default ArrayUtil;
@@ -371,5 +371,32 @@ var ArrayUtil;
371
371
  return result;
372
372
  }
373
373
  ArrayUtil.chunkArray = chunkArray;
374
+ /**
375
+ * 创建一个数组,其中包含原数组的元素,重复一定次数
376
+ * @param originalList [1, 2, 3]
377
+ * @param length 20
378
+ * @returns [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]
379
+ * @example
380
+ * const list = [1, 2, 3];
381
+ * const length = 20;
382
+ * console.log(repeatArray(list, length)); // 输出: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]
383
+ */
384
+ function repeatArray(originalList, length) {
385
+ var repeatedList = [];
386
+ // 计算重复多少次
387
+ var repeatCount = Math.floor(length / originalList.length);
388
+ // 计算剩余的元素数量
389
+ var remainingElements = length % originalList.length;
390
+ // 将原列表重复指定次数
391
+ for (var i = 0; i < repeatCount; i++) {
392
+ repeatedList.push.apply(repeatedList, __spreadArray([], __read(originalList), false)); // 使用扩展运算符将数组合并
393
+ }
394
+ // 如果有剩余的元素,追加到结果中
395
+ if (remainingElements > 0) {
396
+ repeatedList.push.apply(repeatedList, __spreadArray([], __read(originalList.slice(0, remainingElements)), false));
397
+ }
398
+ return repeatedList;
399
+ }
400
+ ArrayUtil.repeatArray = repeatArray;
374
401
  })(ArrayUtil || (ArrayUtil = {}));
375
402
  export default ArrayUtil;
@@ -91,17 +91,17 @@ var TreeUtil;
91
91
  children = 'children';
92
92
  }
93
93
  var list = [];
94
- var fn = function fn(a, c, d) {
94
+ var _fn = function fn(a, c, d) {
95
95
  for (var index = 0; index < ((a === null || a === void 0 ? void 0 : a.length) || 0); index++) {
96
96
  var item = a[index];
97
97
  var back = c(item, d);
98
98
  if (back) {
99
99
  list.push(item);
100
100
  }
101
- fn(item[children], c, item);
101
+ _fn(item[children], c, item);
102
102
  }
103
103
  };
104
- fn(tree, callback, defaultParent);
104
+ _fn(tree, callback, defaultParent);
105
105
  return list;
106
106
  }
107
107
  TreeUtil.filterTreeData = filterTreeData;
@@ -206,19 +206,19 @@ var TreeUtil;
206
206
  return t[value] === id;
207
207
  });
208
208
  var list = getListByTree(tree, children);
209
- var getList = function getList(importOid) {
209
+ var _getList = function getList(importOid) {
210
210
  forEachTree(tree, function (info, _parent) {
211
211
  if (String(info[value]) === String(importOid)) {
212
212
  if (parent in info && info[parent] && list.some(function (e) {
213
213
  return String(e[value]) === String(info[parent]);
214
214
  })) {
215
215
  idList.unshift(_parent);
216
- getList(info === null || info === void 0 ? void 0 : info[parent]);
216
+ _getList(info === null || info === void 0 ? void 0 : info[parent]);
217
217
  }
218
218
  }
219
219
  }, children);
220
220
  };
221
- getList(id);
221
+ _getList(id);
222
222
  if (!BaseUtil.isEmpty(rootPid)) {
223
223
  var idx = idList.findIndex(function (item) {
224
224
  return String(item) === String(rootPid);
@@ -410,19 +410,19 @@ function treeData2List(element, children) {
410
410
  children = 'children';
411
411
  }
412
412
  var array = [];
413
- var getList = function getList(item) {
413
+ var _getList2 = function getList(item) {
414
414
  var _a;
415
415
  var newItem = JSON.parse(JSON.stringify(item || '{}')); //序列化
416
416
  delete newItem[children];
417
417
  if ((_a = item[children]) === null || _a === void 0 ? void 0 : _a.length) {
418
418
  if (!isEmpty(newItem)) array.push(newItem);
419
419
  item[children].forEach(function (el) {
420
- return getList(el);
420
+ return _getList2(el);
421
421
  });
422
422
  } else if (!isEmpty(newItem)) {
423
423
  array.push(newItem);
424
424
  }
425
425
  };
426
- getList(element);
426
+ _getList2(element);
427
427
  return array;
428
428
  }
@@ -462,11 +462,11 @@ function J(e, r, i) {
462
462
  };
463
463
  var a = l.style;
464
464
  a.setProperty("display", "block", "important"), a.position = "absolute", a.top = "0", a.left = "0", a.visibility = "hidden", r && "srcdoc" in l ? l.srcdoc = r : l.src = "about:blank", n.body.appendChild(l);
465
- var c = function c() {
465
+ var _c = function c() {
466
466
  var e, n;
467
- o || ("complete" === (null === (n = null === (e = l.contentWindow) || void 0 === e ? void 0 : e.document) || void 0 === n ? void 0 : n.readyState) ? i() : setTimeout(c, 10));
467
+ o || ("complete" === (null === (n = null === (e = l.contentWindow) || void 0 === e ? void 0 : e.document) || void 0 === n ? void 0 : n.readyState) ? i() : setTimeout(_c, 10));
468
468
  };
469
- c();
469
+ _c();
470
470
  })];
471
471
  case 5:
472
472
  t.sent(), t.label = 6;
@@ -539,10 +539,10 @@ function _() {
539
539
  return r = new Promise(function (e) {
540
540
  var n = document,
541
541
  t = "visibilitychange",
542
- r = function r() {
543
- n.hidden || (n.removeEventListener(t, r), e());
542
+ _r = function r() {
543
+ n.hidden || (n.removeEventListener(t, _r), e());
544
544
  };
545
- n.addEventListener(t, r), r();
545
+ n.addEventListener(t, _r), _r();
546
546
  }).then(function () {
547
547
  return o(500);
548
548
  }), i = function () {
@@ -610,15 +610,15 @@ function O(e) {
610
610
  e.oncomplete = function (e) {
611
611
  return n(e.renderedBuffer);
612
612
  };
613
- var o = function o() {
613
+ var _o = function o() {
614
614
  try {
615
615
  var i = e.startRendering();
616
- a(i) && l(i), "suspended" === e.state && (document.hidden || r--, r > 0 ? setTimeout(o, 200) : n(null));
616
+ a(i) && l(i), "suspended" === e.state && (document.hidden || r--, r > 0 ? setTimeout(_o, 200) : n(null));
617
617
  } catch (c) {
618
618
  t(c);
619
619
  }
620
620
  };
621
- o();
621
+ _o();
622
622
  });
623
623
  }
624
624
  var U = ["monospace", "sans-serif", "serif"],
@@ -698,11 +698,11 @@ function re() {
698
698
  var e = this;
699
699
  return function () {
700
700
  if (void 0 === te) {
701
- var e = function e() {
701
+ var _e2 = function e() {
702
702
  var n = oe();
703
- ie(n) ? te = setTimeout(e, 2500) : (ne = n, te = void 0);
703
+ ie(n) ? te = setTimeout(_e2, 2500) : (ne = n, te = void 0);
704
704
  };
705
- e();
705
+ _e2();
706
706
  }
707
707
  }(), function () {
708
708
  return n(e, void 0, void 0, function () {
@@ -66,6 +66,14 @@ declare namespace DateUtil {
66
66
  * formatDateToFriendly2() => 2017年11月11日
67
67
  */
68
68
  function formatDateToFriendly2(date?: Date | number | string): string;
69
+ /**
70
+ * 将一个日期格式化成友好格式,比如,当天返回几秒前、几分钟前、几小时前、几天前、几个月前还是几年前
71
+ * @param {Date | number | string} date 如: new Date('2017-11-11')
72
+ * @returns {string} 解析后的友好化日期格式
73
+ * @example
74
+ * formatDateToFriendly2() => 2017年11月11日
75
+ */
76
+ function formatDateToFriendly3(date?: Date | number | string): string;
69
77
  /**
70
78
  * 判断是否为本周
71
79
  * @param date
@@ -117,7 +117,10 @@ var DateUtil;
117
117
  dd: ('0' + d.getDate()).slice(-2),
118
118
  HH: ('0' + d.getHours()).slice(-2),
119
119
  mm: ('0' + d.getMinutes()).slice(-2),
120
- ss: ('0' + d.getSeconds()).slice(-2)
120
+ ss: ('0' + d.getSeconds()).slice(-2),
121
+ w: ['日', '一', '二', '三', '四', '五', '六'][d.getDay()],
122
+ q: "".concat(Math.floor((d.getMonth() + 3) / 3)),
123
+ SSS: "".concat(d.getMilliseconds())
121
124
  };
122
125
  var formattedDate = format;
123
126
  for (var char in formatChars) {
@@ -192,6 +195,44 @@ var DateUtil;
192
195
  }
193
196
  }
194
197
  DateUtil.formatDateToFriendly2 = formatDateToFriendly2;
198
+ /**
199
+ * 将一个日期格式化成友好格式,比如,当天返回几秒前、几分钟前、几小时前、几天前、几个月前还是几年前
200
+ * @param {Date | number | string} date 如: new Date('2017-11-11')
201
+ * @returns {string} 解析后的友好化日期格式
202
+ * @example
203
+ * formatDateToFriendly2() => 2017年11月11日
204
+ */
205
+ function formatDateToFriendly3(date) {
206
+ if (date === void 0) {
207
+ date = new Date();
208
+ }
209
+ if (BaseUtil.isString(date)) {
210
+ date = DateUtil.parseDate(date, 'yyyy-MM-dd HH:mm:ss');
211
+ } else {
212
+ date = BaseUtil.isNumber(date) ? new Date(date) : date;
213
+ }
214
+ var currentTime = new Date().getTime(); // 当前时间
215
+ var timeDiff = currentTime - date.getTime(); // 计算时间差
216
+ var seconds = Math.floor(timeDiff / 1000);
217
+ var minutes = Math.floor(seconds / 60);
218
+ var hours = Math.floor(minutes / 60);
219
+ var days = Math.floor(hours / 24);
220
+ var months = Math.floor(days / 30.4375); // 平均每月的天数
221
+ var years = Math.floor(days / 365.25); // 平均每年的天数
222
+ if (seconds < 60) {
223
+ return "".concat(seconds, "\u79D2\u524D");
224
+ } else if (minutes < 60) {
225
+ return "".concat(minutes, "\u5206\u949F\u524D");
226
+ } else if (hours < 24) {
227
+ return "".concat(hours, "\u5C0F\u65F6\u524D");
228
+ } else if (days < 30.4375) {
229
+ return "".concat(days, "\u5929\u524D");
230
+ } else if (months < 12) {
231
+ return "".concat(months, "\u4E2A\u6708\u524D");
232
+ }
233
+ return "".concat(years, "\u5E74\u524D");
234
+ }
235
+ DateUtil.formatDateToFriendly3 = formatDateToFriendly3;
195
236
  /**
196
237
  * 判断是否为本周
197
238
  * @param date
@@ -1,23 +1,23 @@
1
1
  declare namespace FunctionUtil {
2
2
  /**
3
- * 函数柯里化
4
- * @param { Function } fn 方法
5
- * @param { Any } agrs 参数,可选
6
- * @example
7
- * // 实现一个判断数据类型的方法
8
- const checktype = function(type, content) {
9
- return Object.prototype.toString.call(content) === `[object ${type}]`;
10
- }
11
- checktype('Number',2); => true
12
- // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
13
-
14
- const checktype = function(type, content) {
15
- return Object.prototype.toString.call(content) === `[object ${type}]`;
16
- }
17
- const curry = curryFn(checktype)
18
- const isNumber = curry('Number')
19
- isNumber(2) => true
20
- */
3
+ * 函数柯里化
4
+ * @param { Function } fn 方法
5
+ * @param { Any } agrs 参数,可选
6
+ * @example
7
+ * // 实现一个判断数据类型的方法
8
+ const checktype = function(type, content) {
9
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
10
+ }
11
+ checktype('Number',2); => true
12
+ // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
13
+
14
+ const checktype = function(type, content) {
15
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
16
+ }
17
+ const curry = curryFn(checktype)
18
+ const isNumber = curry('Number')
19
+ isNumber(2) => true
20
+ */
21
21
  function curryFn(fn: any, ...arg: any): () => any;
22
22
  /**
23
23
  * 函数防抖
@@ -35,7 +35,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
35
35
  * @author nanshen
36
36
  * @creat 2021-09-15 14:22:55
37
37
  */
38
- import BaseUtil from "../base/BaseUtil";
38
+ import BaseUtil from '../base/BaseUtil';
39
39
  var FunctionUtil;
40
40
  (function (FunctionUtil) {
41
41
  /**
@@ -44,25 +44,25 @@ var FunctionUtil;
44
44
  * @param { Any } agrs 参数,可选
45
45
  * @example
46
46
  * // 实现一个判断数据类型的方法
47
- const checktype = function(type, content) {
48
- return Object.prototype.toString.call(content) === `[object ${type}]`;
49
- }
50
- checktype('Number',2); => true
51
- // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
52
-
53
- const checktype = function(type, content) {
54
- return Object.prototype.toString.call(content) === `[object ${type}]`;
55
- }
56
- const curry = curryFn(checktype)
57
- const isNumber = curry('Number')
58
- isNumber(2) => true
59
- */
47
+ const checktype = function(type, content) {
48
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
49
+ }
50
+ checktype('Number',2); => true
51
+ // 这种方法总是要把type参数传过去,如果写错了就会影响到正确的结果了,可以考虑下如何做到把“Number“做到复用
52
+
53
+ const checktype = function(type, content) {
54
+ return Object.prototype.toString.call(content) === `[object ${type}]`;
55
+ }
56
+ const curry = curryFn(checktype)
57
+ const isNumber = curry('Number')
58
+ isNumber(2) => true
59
+ */
60
60
  function curryFn(fn) {
61
61
  var arg = [];
62
62
  for (var _i = 1; _i < arguments.length; _i++) {
63
63
  arg[_i - 1] = arguments[_i];
64
64
  }
65
- if (!BaseUtil.isFunction(fn)) throw new Error("第一个参数必须是方法");
65
+ if (!BaseUtil.isFunction(fn)) throw new Error('第一个参数必须是方法');
66
66
  var _this = this;
67
67
  var args = Array.from(arguments).slice(1);
68
68
  // fn.length 属性指明函数的形参个数。
@@ -99,7 +99,7 @@ var FunctionUtil;
99
99
  if (immediate === void 0) {
100
100
  immediate = true;
101
101
  }
102
- if (!BaseUtil.isFunction(fn)) throw new Error("第一个参数必须是方法");
102
+ if (!BaseUtil.isFunction(fn)) throw new Error('第一个参数必须是方法');
103
103
  var time;
104
104
  // 立刻执行第一次该方法
105
105
  if (immediate) {
@@ -142,7 +142,7 @@ var FunctionUtil;
142
142
  if (t === void 0) {
143
143
  t = 2000;
144
144
  }
145
- if (!BaseUtil.isFunction(fn)) throw new Error("第一个参数必须是方法");
145
+ if (!BaseUtil.isFunction(fn)) throw new Error('第一个参数必须是方法');
146
146
  var _fn = fn;
147
147
  var time = null;
148
148
  var first = true;
@@ -174,7 +174,7 @@ var FunctionUtil;
174
174
  * // 1
175
175
  */
176
176
  function once(fn) {
177
- if (!BaseUtil.isFunction(fn)) throw new Error("参数必须是方法");
177
+ if (!BaseUtil.isFunction(fn)) throw new Error('参数必须是方法');
178
178
  var result;
179
179
  return function () {
180
180
  if (fn) {
@@ -89,8 +89,9 @@ declare namespace NumberUtil {
89
89
  * n在count中的占比%
90
90
  * @param n
91
91
  * @param count
92
+ * @param m 小数位数 默认为2
92
93
  * @returns
93
94
  */
94
- const number2percentage: (n: number, count: number) => string;
95
+ const number2percentage: (n: number, count: number, m?: number) => string;
95
96
  }
96
97
  export default NumberUtil;
@@ -241,10 +241,14 @@ var NumberUtil;
241
241
  * n在count中的占比%
242
242
  * @param n
243
243
  * @param count
244
+ * @param m 小数位数 默认为2
244
245
  * @returns
245
246
  */
246
- NumberUtil.number2percentage = function (n, count) {
247
- return "".concat(count ? correctNumberInput((n || 0) * 100 / count, 2) : 0, "%");
247
+ NumberUtil.number2percentage = function (n, count, m) {
248
+ if (m === void 0) {
249
+ m = 2;
250
+ }
251
+ return "".concat(count ? correctNumberInput((n || 0) * 100 / count, m) : 0, "%");
248
252
  };
249
253
  })(NumberUtil || (NumberUtil = {}));
250
254
  export default NumberUtil;
@@ -29,5 +29,33 @@ declare namespace PasswordUtil {
29
29
  * str2MD5('1111') => ea69274f6555a750bec9985a07f80455
30
30
  */
31
31
  const str2MD5: (str: string, pwd?: string) => any;
32
+ /**
33
+ * 加密函数
34
+ * @param {Object} data - 要加密的 JSON 对象
35
+ * @param {string} key - 密钥
36
+ * @returns {string} 加密并编码后的字符串
37
+ */
38
+ function xorEncryptData(data: any, pwd?: string): string;
39
+ /**
40
+ * 解密函数
41
+ * @param {string} encodedData - 加密并编码后的字符串
42
+ * @param {string} pwd - 密钥
43
+ * @returns {Object} 解密后的 JSON 对象
44
+ */
45
+ function xorDecryptData(encodedData: string, pwd?: string): any;
46
+ /**
47
+ * 加密函数
48
+ * @param {Object} data - 要加密的 JSON 对象
49
+ * @param {string} key - 密钥
50
+ * @returns {string} 加密并编码后的字符串
51
+ */
52
+ function minEncryptData(data: any, pwd?: string): string;
53
+ /**
54
+ * 解密函数
55
+ * @param {string} encodedData - 加密并编码后的字符串
56
+ * @param {string} pwd - 密钥
57
+ * @returns {Object} 解密后的 JSON 对象
58
+ */
59
+ function minDecryptData(encodedData: string, pwd?: string): any;
32
60
  }
33
61
  export default PasswordUtil;
@@ -1,6 +1,6 @@
1
1
  import config from '../config';
2
- import crypto from './crypto';
3
- var CryptoJS = crypto();
2
+ import CryptoJS from './crypto';
3
+ import LZString from './lz-string';
4
4
  /**
5
5
  * 加密工具
6
6
  * @description
@@ -64,5 +64,92 @@ var PasswordUtil;
64
64
  if (!str) return '';
65
65
  return CryptoJS.MD5(pwd + str).toString();
66
66
  };
67
+ /**
68
+ * 加密函数
69
+ * @param {Object} data - 要加密的 JSON 对象
70
+ * @param {string} key - 密钥
71
+ * @returns {string} 加密并编码后的字符串
72
+ */
73
+ function xorEncryptData(data, pwd) {
74
+ if (pwd === void 0) {
75
+ pwd = defaultMD5Key;
76
+ }
77
+ var jsonString = JSON.stringify(data); // 将对象转为字符串
78
+ var compressed = LZString.compressToUTF16(jsonString); // 压缩数据
79
+ var encrypted = xorEncryptDecrypt(compressed, pwd); // XOR 加密
80
+ var encoded = LZString.compressToEncodedURIComponent(encrypted); // URL 安全编码
81
+ return encoded;
82
+ }
83
+ PasswordUtil.xorEncryptData = xorEncryptData;
84
+ /**
85
+ * 解密函数
86
+ * @param {string} encodedData - 加密并编码后的字符串
87
+ * @param {string} pwd - 密钥
88
+ * @returns {Object} 解密后的 JSON 对象
89
+ */
90
+ function xorDecryptData(encodedData, pwd) {
91
+ if (pwd === void 0) {
92
+ pwd = defaultMD5Key;
93
+ }
94
+ try {
95
+ var decryptedEncoded = LZString.decompressFromEncodedURIComponent(encodedData); // 解码
96
+ if (!decryptedEncoded) {
97
+ throw new Error('Failed to decompress encoded data.');
98
+ }
99
+ var decrypted = xorEncryptDecrypt(decryptedEncoded, pwd); // XOR 解密
100
+ var decompressed = LZString.decompressFromUTF16(decrypted); // 解压
101
+ if (!decompressed) {
102
+ throw new Error('Failed to decompress decrypted data.');
103
+ }
104
+ return JSON.parse(decompressed); // 解析 JSON
105
+ } catch (error) {
106
+ return '';
107
+ }
108
+ }
109
+ PasswordUtil.xorDecryptData = xorDecryptData;
110
+ /**
111
+ * 加密函数
112
+ * @param {Object} data - 要加密的 JSON 对象
113
+ * @param {string} key - 密钥
114
+ * @returns {string} 加密并编码后的字符串
115
+ */
116
+ function minEncryptData(data, pwd) {
117
+ if (pwd === void 0) {
118
+ pwd = defaultMD5Key;
119
+ }
120
+ return encodeURIComponent(xorEncryptDecrypt(JSON.stringify(data), pwd));
121
+ }
122
+ PasswordUtil.minEncryptData = minEncryptData;
123
+ /**
124
+ * 解密函数
125
+ * @param {string} encodedData - 加密并编码后的字符串
126
+ * @param {string} pwd - 密钥
127
+ * @returns {Object} 解密后的 JSON 对象
128
+ */
129
+ function minDecryptData(encodedData, pwd) {
130
+ if (pwd === void 0) {
131
+ pwd = defaultMD5Key;
132
+ }
133
+ try {
134
+ return JSON.parse(xorEncryptDecrypt(decodeURIComponent(encodedData), pwd)); // 解析 JSON
135
+ } catch (error) {
136
+ return undefined;
137
+ }
138
+ }
139
+ PasswordUtil.minDecryptData = minDecryptData;
67
140
  })(PasswordUtil || (PasswordUtil = {}));
68
- export default PasswordUtil;
141
+ export default PasswordUtil;
142
+ /**
143
+ * XOR 加密与解密函数
144
+ * @param {string} data - 要加密或解密的字符串
145
+ * @param {string} pwd - 密钥
146
+ * @returns {string} 加密或解密后的字符串
147
+ */
148
+ function xorEncryptDecrypt(data, pwd) {
149
+ var keyLength = pwd.length;
150
+ var result = '';
151
+ for (var i = 0; i < data.length; i++) {
152
+ result += String.fromCharCode(data.charCodeAt(i) ^ pwd.charCodeAt(i % keyLength));
153
+ }
154
+ return result;
155
+ }
@@ -1,6 +1,6 @@
1
- export default cryptoFn;
2
- declare function cryptoFn(): {
3
- lib: {};
4
- enc: {};
5
- algo: {};
6
- };
1
+ export default CryptoJS;
2
+ declare namespace CryptoJS {
3
+ const lib: {};
4
+ const enc: {};
5
+ const algo: {};
6
+ }
package/esm/pwd/crypto.js CHANGED
@@ -1,4 +1,4 @@
1
- function cryptoFn() {
1
+ var CryptoJS = function () {
2
2
  var n,
3
3
  o,
4
4
  s,
@@ -1820,5 +1820,5 @@ function cryptoFn() {
1820
1820
  blockSize: 4,
1821
1821
  ivSize: 2
1822
1822
  }), M.RabbitLegacy = F._createHelper(P), U;
1823
- }
1824
- export default cryptoFn;
1823
+ }();
1824
+ export default CryptoJS;
@@ -0,0 +1,15 @@
1
+ export default LZString;
2
+ declare namespace LZString {
3
+ function compressToBase64(input: any): string;
4
+ function decompressFromBase64(input: any): string | null;
5
+ function compressToUTF16(input: any): string;
6
+ function decompressFromUTF16(compressed: any): string | null;
7
+ function compressToUint8Array(uncompressed: any): Uint8Array;
8
+ function decompressFromUint8Array(compressed: any): string | null;
9
+ function compressToEncodedURIComponent(input: any): string;
10
+ function decompressFromEncodedURIComponent(input: any): string | null;
11
+ function compress(uncompressed: any): string;
12
+ function _compress(uncompressed: any, bitsPerChar: any, getCharFromInt: any): string;
13
+ function decompress(compressed: any): string | null;
14
+ function _decompress(length: any, resetValue: any, getNextValue: any): string | null;
15
+ }