tools-min-ns 1.5.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 (162) hide show
  1. package/README.md +85 -0
  2. package/esm/array/ArrayUtil.d.ts +109 -0
  3. package/esm/array/ArrayUtil.js +242 -0
  4. package/esm/array/TreeUtil.d.ts +151 -0
  5. package/esm/array/TreeUtil.js +412 -0
  6. package/esm/base/BaseUtil.d.ts +91 -0
  7. package/esm/base/BaseUtil.js +148 -0
  8. package/esm/browser/BrowserUtil.d.ts +57 -0
  9. package/esm/browser/BrowserUtil.js +337 -0
  10. package/esm/browser/fingerprint.d.ts +120 -0
  11. package/esm/browser/fingerprint.js +1469 -0
  12. package/esm/check/CheckUtil.d.ts +110 -0
  13. package/esm/check/CheckUtil.js +465 -0
  14. package/esm/common.d.ts +43 -0
  15. package/esm/common.js +44 -0
  16. package/esm/config.d.ts +7 -0
  17. package/esm/config.js +7 -0
  18. package/esm/cookie/CookieUtil.d.ts +56 -0
  19. package/esm/cookie/CookieUtil.js +12 -0
  20. package/esm/cookie/cookie.d.ts +2 -0
  21. package/esm/cookie/cookie.js +104 -0
  22. package/esm/date/DateUtil.d.ts +261 -0
  23. package/esm/date/DateUtil.js +763 -0
  24. package/esm/env/EnvUtil.d.ts +27 -0
  25. package/esm/env/EnvUtil.js +29 -0
  26. package/esm/env/env.d.ts +41 -0
  27. package/esm/env/env.js +106 -0
  28. package/esm/func/FunctionUtil.d.ts +77 -0
  29. package/esm/func/FunctionUtil.js +215 -0
  30. package/esm/index.d.ts +19 -0
  31. package/esm/index.js +19 -0
  32. package/esm/number/NumberUtil.d.ts +96 -0
  33. package/esm/number/NumberUtil.js +256 -0
  34. package/esm/object/ObjectUtil.d.ts +41 -0
  35. package/esm/object/ObjectUtil.js +158 -0
  36. package/esm/pwd/PasswordUtil.d.ts +33 -0
  37. package/esm/pwd/PasswordUtil.js +68 -0
  38. package/esm/pwd/crypto.d.ts +6 -0
  39. package/esm/pwd/crypto.js +1824 -0
  40. package/esm/request/RequestUtil.d.ts +52 -0
  41. package/esm/request/RequestUtil.js +53 -0
  42. package/esm/request/jsonp.d.ts +18 -0
  43. package/esm/request/jsonp.js +73 -0
  44. package/esm/request/mgop/env.d.ts +7 -0
  45. package/esm/request/mgop/env.js +15 -0
  46. package/esm/request/mgop/index.d.ts +3 -0
  47. package/esm/request/mgop/index.js +276 -0
  48. package/esm/request/mgop/responseCode.d.ts +20 -0
  49. package/esm/request/mgop/responseCode.js +37 -0
  50. package/esm/request/mgop/type.d.ts +34 -0
  51. package/esm/request/mgop/type.js +1 -0
  52. package/esm/request/uniRquest/index.d.ts +2 -0
  53. package/esm/request/uniRquest/index.js +66 -0
  54. package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
  55. package/esm/request/uniRquest/miniapp/index.js +29 -0
  56. package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  57. package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
  58. package/esm/request/uniRquest/types.d.ts +65 -0
  59. package/esm/request/uniRquest/types.js +36 -0
  60. package/esm/request/uniRquest/utils.d.ts +9 -0
  61. package/esm/request/uniRquest/utils.js +69 -0
  62. package/esm/request/uniRquest/web/index.d.ts +2 -0
  63. package/esm/request/uniRquest/web/index.js +85 -0
  64. package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  65. package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
  66. package/esm/request/uniRquest/weex/index.d.ts +14 -0
  67. package/esm/request/uniRquest/weex/index.js +59 -0
  68. package/esm/storage/StorageUtil.d.ts +19 -0
  69. package/esm/storage/StorageUtil.js +75 -0
  70. package/esm/string/StringUtil.d.ts +392 -0
  71. package/esm/string/StringUtil.js +556 -0
  72. package/esm/system/SystemUtil.d.ts +46 -0
  73. package/esm/system/SystemUtil.js +122 -0
  74. package/esm/transfer/MapTransferUtil.d.ts +54 -0
  75. package/esm/transfer/MapTransferUtil.js +160 -0
  76. package/esm/transfer/TransferUtil.d.ts +98 -0
  77. package/esm/transfer/TransferUtil.js +323 -0
  78. package/esm/types.d.ts +25 -0
  79. package/esm/types.js +1 -0
  80. package/esm/url/UrlUtil.d.ts +30 -0
  81. package/esm/url/UrlUtil.js +85 -0
  82. package/lib/array/ArrayUtil.d.ts +109 -0
  83. package/lib/array/ArrayUtil.js +252 -0
  84. package/lib/array/TreeUtil.d.ts +151 -0
  85. package/lib/array/TreeUtil.js +422 -0
  86. package/lib/base/BaseUtil.d.ts +91 -0
  87. package/lib/base/BaseUtil.js +153 -0
  88. package/lib/browser/BrowserUtil.d.ts +57 -0
  89. package/lib/browser/BrowserUtil.js +347 -0
  90. package/lib/browser/fingerprint.d.ts +120 -0
  91. package/lib/browser/fingerprint.js +1500 -0
  92. package/lib/check/CheckUtil.d.ts +110 -0
  93. package/lib/check/CheckUtil.js +475 -0
  94. package/lib/common.d.ts +43 -0
  95. package/lib/common.js +50 -0
  96. package/lib/config.d.ts +7 -0
  97. package/lib/config.js +12 -0
  98. package/lib/cookie/CookieUtil.d.ts +56 -0
  99. package/lib/cookie/CookieUtil.js +22 -0
  100. package/lib/cookie/cookie.d.ts +2 -0
  101. package/lib/cookie/cookie.js +109 -0
  102. package/lib/date/DateUtil.d.ts +261 -0
  103. package/lib/date/DateUtil.js +773 -0
  104. package/lib/env/EnvUtil.d.ts +27 -0
  105. package/lib/env/EnvUtil.js +39 -0
  106. package/lib/env/env.d.ts +41 -0
  107. package/lib/env/env.js +112 -0
  108. package/lib/func/FunctionUtil.d.ts +77 -0
  109. package/lib/func/FunctionUtil.js +225 -0
  110. package/lib/index.d.ts +19 -0
  111. package/lib/index.js +144 -0
  112. package/lib/number/NumberUtil.d.ts +96 -0
  113. package/lib/number/NumberUtil.js +266 -0
  114. package/lib/object/ObjectUtil.d.ts +41 -0
  115. package/lib/object/ObjectUtil.js +168 -0
  116. package/lib/pwd/PasswordUtil.d.ts +33 -0
  117. package/lib/pwd/PasswordUtil.js +78 -0
  118. package/lib/pwd/crypto.d.ts +6 -0
  119. package/lib/pwd/crypto.js +1829 -0
  120. package/lib/request/RequestUtil.d.ts +52 -0
  121. package/lib/request/RequestUtil.js +94 -0
  122. package/lib/request/jsonp.d.ts +18 -0
  123. package/lib/request/jsonp.js +80 -0
  124. package/lib/request/mgop/env.d.ts +7 -0
  125. package/lib/request/mgop/env.js +21 -0
  126. package/lib/request/mgop/index.d.ts +3 -0
  127. package/lib/request/mgop/index.js +289 -0
  128. package/lib/request/mgop/responseCode.d.ts +20 -0
  129. package/lib/request/mgop/responseCode.js +42 -0
  130. package/lib/request/mgop/type.d.ts +34 -0
  131. package/lib/request/mgop/type.js +5 -0
  132. package/lib/request/uniRquest/index.d.ts +2 -0
  133. package/lib/request/uniRquest/index.js +77 -0
  134. package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
  135. package/lib/request/uniRquest/miniapp/index.js +35 -0
  136. package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  137. package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
  138. package/lib/request/uniRquest/types.d.ts +65 -0
  139. package/lib/request/uniRquest/types.js +42 -0
  140. package/lib/request/uniRquest/utils.d.ts +9 -0
  141. package/lib/request/uniRquest/utils.js +83 -0
  142. package/lib/request/uniRquest/web/index.d.ts +2 -0
  143. package/lib/request/uniRquest/web/index.js +91 -0
  144. package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  145. package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
  146. package/lib/request/uniRquest/weex/index.d.ts +14 -0
  147. package/lib/request/uniRquest/weex/index.js +65 -0
  148. package/lib/storage/StorageUtil.d.ts +19 -0
  149. package/lib/storage/StorageUtil.js +85 -0
  150. package/lib/string/StringUtil.d.ts +392 -0
  151. package/lib/string/StringUtil.js +566 -0
  152. package/lib/system/SystemUtil.d.ts +46 -0
  153. package/lib/system/SystemUtil.js +132 -0
  154. package/lib/transfer/MapTransferUtil.d.ts +54 -0
  155. package/lib/transfer/MapTransferUtil.js +165 -0
  156. package/lib/transfer/TransferUtil.d.ts +98 -0
  157. package/lib/transfer/TransferUtil.js +333 -0
  158. package/lib/types.d.ts +25 -0
  159. package/lib/types.js +5 -0
  160. package/lib/url/UrlUtil.d.ts +30 -0
  161. package/lib/url/UrlUtil.js +95 -0
  162. package/package.json +56 -0
@@ -0,0 +1,256 @@
1
+ /**
2
+ * 数字工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 14:23:13
6
+ */
7
+ import BaseUtil from "../base/BaseUtil";
8
+ var NumberUtil;
9
+ (function (NumberUtil) {
10
+ /**
11
+ * 判断是否为整数
12
+ * @param {Number} num 数字
13
+ */
14
+ NumberUtil.isInteger = function (num) {
15
+ return BaseUtil.isNumber(num) && isFinite(num) && Math.floor(num) === num;
16
+ };
17
+ /**
18
+ * 判断是否为小数
19
+ * @param {Number} num 数字
20
+ */
21
+ NumberUtil.isFloat = function (num) {
22
+ return BaseUtil.isNumber(num) && isFinite(num) && Math.floor(num) !== num;
23
+ };
24
+ /**
25
+ * 判断是否是 NaN
26
+ * @param num 数字
27
+ */
28
+ NumberUtil.isaNaN = function (num) {
29
+ return BaseUtil.isNumber(num) && isNaN(num);
30
+ };
31
+ /**
32
+ * 判断是否是有理数
33
+ * @param num 数字
34
+ */
35
+ NumberUtil.isaFinite = function (num) {
36
+ return BaseUtil.isNumber(num) && isFinite(num);
37
+ };
38
+ /**
39
+ * 转为数字
40
+ * @param value 要转成数字的值
41
+ */
42
+ var toNumber = function toNumber(value) {
43
+ return Number(value);
44
+ };
45
+ /**
46
+ * 转为有理数
47
+ * @param value 要转换的值
48
+ *
49
+ * @example
50
+ * toFinite(3.2) => 3.2
51
+ * toFinite(Infinity) => 1.7976e+308
52
+ * toFinite('3.2') => 3.2
53
+ */
54
+ NumberUtil.toFinite = function (value) {
55
+ if (!value) {
56
+ return 0;
57
+ }
58
+ value = toNumber(value);
59
+ if (value === Infinity || value === -Infinity) {
60
+ var sign = value < 0 ? -1 : 1;
61
+ return sign * Number.MAX_SAFE_INTEGER;
62
+ }
63
+ return value === value ? value : 0;
64
+ };
65
+ /**
66
+ * 检查数字是否在指定区间内
67
+ * @param num 要检测的数字
68
+ * @param start 区间的开始,默认值为0
69
+ * @param end 区间的结束(区间不包含此边界值)
70
+ * @example
71
+ * inRange(10,1,100) => true
72
+ */
73
+ NumberUtil.inRange = function (num, start, end) {
74
+ start = NumberUtil.toFinite(start);
75
+ if (end === undefined) {
76
+ end = start;
77
+ start = 0;
78
+ } else {
79
+ end = NumberUtil.toFinite(end);
80
+ }
81
+ num = toNumber(num);
82
+ return baseInRange(num, start, end);
83
+ };
84
+ var baseInRange = function baseInRange(num, start, end) {
85
+ return num >= Math.min(start, end) && num < Math.max(start, end);
86
+ };
87
+ /**
88
+ * 生成随机数,支持随机整数和随机小数
89
+ * @param {Number} lower 下边界,默认0
90
+ * @param {Number} upper 上边界,默认1
91
+ * @param {Boolean} floating 随机小数的位数,默认为0,即随机整数
92
+ *
93
+ * @example
94
+ * random(0, 5) => an integer between 0 and 5
95
+ * random(5) => also random(0, 5)
96
+ * random(1.2, 5.2, 1) => a floating-point number between 1.2 and 5.2
97
+ */
98
+ NumberUtil.random = function (lower, upper, floating) {
99
+ if (floating === void 0) {
100
+ floating = 0;
101
+ }
102
+ // 参数调整
103
+ if (lower === undefined && upper === undefined) {
104
+ lower = 0;
105
+ upper = 1;
106
+ } else {
107
+ lower = NumberUtil.toFinite(lower);
108
+ if (upper === undefined) {
109
+ upper = lower;
110
+ lower = 0;
111
+ } else {
112
+ upper = NumberUtil.toFinite(upper);
113
+ }
114
+ }
115
+ if (lower > upper) {
116
+ var temp = lower;
117
+ lower = upper;
118
+ upper = temp;
119
+ }
120
+ var rand = Math.random();
121
+ if (floating || lower % 1 || upper % 1) {
122
+ // 浮点数
123
+ var t = lower + rand * (upper - lower + parseFloat("1e-" + ((rand + "").length - 1)));
124
+ return toNumber(Math.min(t, upper).toFixed(floating));
125
+ } else {
126
+ // 整数
127
+ return lower + Math.floor(rand * (upper - lower + 1));
128
+ }
129
+ };
130
+ /**
131
+ * 保留n位小数
132
+ * @param val 任意类型
133
+ * @param n 小数位数
134
+ * @returns 不是string|number 返回0
135
+ */
136
+ function correctNumberInput(val, n, type) {
137
+ if (n === void 0) {
138
+ n = 2;
139
+ }
140
+ if (type === void 0) {
141
+ type = "number";
142
+ }
143
+ if (undefined == val || null == val || "" == val || isNaN(val)) {
144
+ return 0;
145
+ }
146
+ var lastChar = val[val.length - 1] === "." ? "." : "";
147
+ var str = (isNaN(parseFloat(val)) ? "" : parseInt("".concat(Math.round(parseFloat(val) * Math.pow(10, n)))) / Math.pow(10, n)) + lastChar;
148
+ return type === "number" ? Number(str) : str;
149
+ }
150
+ NumberUtil.correctNumberInput = correctNumberInput;
151
+ /**
152
+ * 解决两个数相加精度丢失问题
153
+ * @param a 任意类型
154
+ * @param b 任意类型
155
+ * @returns {Number} 错误返回0
156
+ */
157
+ function floatAdd(a, b) {
158
+ var c, d, e;
159
+ if (undefined == a || null == a || "" == a || isNaN(a)) {
160
+ a = 0;
161
+ }
162
+ if (undefined == b || null == b || "" == b || isNaN(b)) {
163
+ b = 0;
164
+ }
165
+ try {
166
+ c = a.toString().split(".")[1].length;
167
+ } catch (f) {
168
+ c = 0;
169
+ }
170
+ try {
171
+ d = b.toString().split(".")[1].length;
172
+ } catch (f) {
173
+ d = 0;
174
+ }
175
+ e = Math.pow(10, Math.max(c, d));
176
+ return (floatMul(a, e) + floatMul(b, e)) / e;
177
+ }
178
+ NumberUtil.floatAdd = floatAdd;
179
+ /**
180
+ * 解决两个数相减精度丢失问题
181
+ * @param a 任意类型
182
+ * @param b 任意类型
183
+ * @returns {Number}错误返回0
184
+ */
185
+ function floatSub(a, b) {
186
+ var c, d, e;
187
+ if (undefined == a || null == a || "" == a || isNaN(a)) {
188
+ a = 0;
189
+ }
190
+ if (undefined == b || null == b || "" == b || isNaN(b)) {
191
+ b = 0;
192
+ }
193
+ try {
194
+ c = a.toString().split(".")[1].length;
195
+ } catch (f) {
196
+ c = 0;
197
+ }
198
+ try {
199
+ d = b.toString().split(".")[1].length;
200
+ } catch (f) {
201
+ d = 0;
202
+ }
203
+ e = Math.pow(10, Math.max(c, d));
204
+ return (floatMul(a, e) - floatMul(b, e)) / e;
205
+ }
206
+ NumberUtil.floatSub = floatSub;
207
+ /**
208
+ * 解决两个数相乘精度丢失问题
209
+ * @param a 任意类型
210
+ * @param b 任意类型
211
+ * @returns {Number}
212
+ */
213
+ function floatMul(a, b) {
214
+ var c = 0,
215
+ d = a.toString(),
216
+ e = b.toString();
217
+ try {
218
+ c += d.split(".")[1].length;
219
+ } catch (f) {}
220
+ try {
221
+ c += e.split(".")[1].length;
222
+ } catch (f) {}
223
+ return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
224
+ }
225
+ NumberUtil.floatMul = floatMul;
226
+ /**
227
+ * 解决两个数相除精度丢失问题
228
+ * @param a 任意类型
229
+ * @param b 任意类型
230
+ * @returns 错误返回0
231
+ */
232
+ function floatDiv(a, b) {
233
+ var c,
234
+ d,
235
+ e = 0,
236
+ f = 0;
237
+ try {
238
+ e = a.toString().split(".")[1].length;
239
+ } catch (g) {}
240
+ try {
241
+ f = b.toString().split(".")[1].length;
242
+ } catch (g) {}
243
+ return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), floatMul(c / d, Math.pow(10, f - e));
244
+ }
245
+ NumberUtil.floatDiv = floatDiv;
246
+ /**
247
+ * n在count中的占比%
248
+ * @param n
249
+ * @param count
250
+ * @returns
251
+ */
252
+ NumberUtil.number2percentage = function (n, count) {
253
+ return "".concat(count ? correctNumberInput((n || 0) * 100 / count, 2, "string") : 0, "%");
254
+ };
255
+ })(NumberUtil || (NumberUtil = {}));
256
+ export default NumberUtil;
@@ -0,0 +1,41 @@
1
+ declare namespace ObjectUtil {
2
+ /**
3
+ * @description 深度克隆
4
+ * @param {*} source
5
+ * @example
6
+ * const source = {a:1,b:2}
7
+ * deepClone(source) =>{a:1,b:2}
8
+ */
9
+ function deepClone<T>(source: T): T;
10
+ /**
11
+ * 读取对象的值
12
+ * @param object 对象
13
+ * @param path 路径点分隔 例如 a.b.c
14
+ * @param defaultValue 默认值
15
+ */
16
+ function getObjectValue(object: Record<any, any>, path: string, defaultValue?: any): any;
17
+ /**
18
+ * 设置对象的值
19
+ * @param object 对象
20
+ * @param path 路径点分隔 例如 a.b.c
21
+ * @param value 值
22
+ * @param isChangeOriginObj 是否改变原对象 默认false
23
+ */
24
+ function setObjValue<T = any, N = any>(object: T, path: string, value?: any, isChangeOriginObj?: boolean): N;
25
+ /**
26
+ * 对象所有属性设置相同的值
27
+ * @param object 对象
28
+ * @param value 值
29
+ * @param isChangeOriginObj 是否改变原对象 默认false
30
+ */
31
+ function setObjSameValue<T = any, N = any>(object: T, value?: N, isChangeOriginObj?: boolean): Record<keyof typeof object, N> | undefined;
32
+ /**
33
+ * 合并AB对象,A对象没有的属性则去取B对象
34
+ * A优先级高于B
35
+ * @param paramsA 对象
36
+ * @param paramsB 对象
37
+ * @returns
38
+ */
39
+ function mergeParams<A, B>(paramsA: A, paramsB: B): A & Required<B>;
40
+ }
41
+ export default ObjectUtil;
@@ -0,0 +1,158 @@
1
+ var __read = this && this.__read || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o),
5
+ r,
6
+ ar = [],
7
+ e;
8
+ try {
9
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
10
+ } catch (error) {
11
+ e = {
12
+ error: error
13
+ };
14
+ } finally {
15
+ try {
16
+ if (r && !r.done && (m = i["return"])) m.call(i);
17
+ } finally {
18
+ if (e) throw e.error;
19
+ }
20
+ }
21
+ return ar;
22
+ };
23
+ /**
24
+ * 对象工具
25
+ * @description
26
+ * @author nanshen
27
+ * @creat 2021-09-15 14:23:23
28
+ */
29
+ import BaseUtil from "../base/BaseUtil";
30
+ var isObject = BaseUtil.isObject,
31
+ isArray = BaseUtil.isArray;
32
+ var ObjectUtil;
33
+ (function (ObjectUtil) {
34
+ /**
35
+ * @description 深度克隆
36
+ * @param {*} source
37
+ * @example
38
+ * const source = {a:1,b:2}
39
+ * deepClone(source) =>{a:1,b:2}
40
+ */
41
+ function deepClone(source) {
42
+ var target;
43
+ if (isObject(source)) {
44
+ target = {};
45
+ for (var key in source) {
46
+ target[key] = deepClone(source[key]);
47
+ }
48
+ } else if (isArray(source)) {
49
+ target = [];
50
+ for (var i = 0, len = source.length; i < len; i++) {
51
+ target.push(deepClone(source[i]));
52
+ }
53
+ } else {
54
+ return source;
55
+ }
56
+ return target;
57
+ }
58
+ ObjectUtil.deepClone = deepClone;
59
+ /**
60
+ * 读取对象的值
61
+ * @param object 对象
62
+ * @param path 路径点分隔 例如 a.b.c
63
+ * @param defaultValue 默认值
64
+ */
65
+ function getObjectValue(object, path, defaultValue) {
66
+ // 判断 object 是否是数组或者对象,否则直接返回默认值 defaultValue
67
+ if (!BaseUtil.isObject(object)) return defaultValue;
68
+ // 沿着路径寻找到对应的值,未找到则返回默认值 defaultValue
69
+ return path.split(".").reduce(function (o, k) {
70
+ return (o || {})[k];
71
+ }, object) || defaultValue;
72
+ }
73
+ ObjectUtil.getObjectValue = getObjectValue;
74
+ /**
75
+ * 设置对象的值
76
+ * @param object 对象
77
+ * @param path 路径点分隔 例如 a.b.c
78
+ * @param value 值
79
+ * @param isChangeOriginObj 是否改变原对象 默认false
80
+ */
81
+ function setObjValue(object, path, value, isChangeOriginObj) {
82
+ if (!BaseUtil.isObject(object)) return object;
83
+ var newObj = isChangeOriginObj ? object : deepClone(object);
84
+ path.split(".").reduce(function (o, k, i, _) {
85
+ if (i === _.length - 1) {
86
+ // 若遍历结束直接赋值
87
+ o[k] = value;
88
+ return null;
89
+ } else if (k in o) {
90
+ // 若存在对应路径,则返回找到的对象,进行下一次遍历
91
+ return o[k];
92
+ } else {
93
+ // 若不存在对应路径,则创建对应对象,若下一路径是数字,新对象赋值为空数组,否则赋值为空对象
94
+ o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {};
95
+ return o[k];
96
+ }
97
+ }, newObj);
98
+ // 返回newObj
99
+ return newObj;
100
+ }
101
+ ObjectUtil.setObjValue = setObjValue;
102
+ /**
103
+ * 对象所有属性设置相同的值
104
+ * @param object 对象
105
+ * @param value 值
106
+ * @param isChangeOriginObj 是否改变原对象 默认false
107
+ */
108
+ function setObjSameValue(object, value, isChangeOriginObj) {
109
+ if (!BaseUtil.isObject(object)) return;
110
+ var data = {};
111
+ Object.keys(object || {}).forEach(function (k) {
112
+ if (isChangeOriginObj) {
113
+ object[k] = value;
114
+ return;
115
+ }
116
+ data[k] = value;
117
+ });
118
+ return isChangeOriginObj ? object : data;
119
+ }
120
+ ObjectUtil.setObjSameValue = setObjSameValue;
121
+ /**
122
+ * 合并AB对象,A对象没有的属性则去取B对象
123
+ * A优先级高于B
124
+ * @param paramsA 对象
125
+ * @param paramsB 对象
126
+ * @returns
127
+ */
128
+ function mergeParams(paramsA, paramsB) {
129
+ var isAObj = BaseUtil.isObject(paramsA);
130
+ var isBObj = BaseUtil.isObject(paramsB);
131
+ if (!isAObj && !isBObj) return {};
132
+ if (BaseUtil.isEmpty(paramsA) || !isAObj) return paramsB;
133
+ if (BaseUtil.isEmpty(paramsB) || !isBObj) return paramsA;
134
+ var dataAllMap = new Map();
135
+ Object.entries(paramsA || {}).forEach(function (_a) {
136
+ var _b = __read(_a, 2),
137
+ k = _b[0],
138
+ v = _b[1];
139
+ dataAllMap.set(k, v);
140
+ }); //浅拷贝A属性
141
+ Object.entries(paramsB || {}).forEach(function (_a) {
142
+ var _b = __read(_a, 2),
143
+ k = _b[0],
144
+ v = _b[1];
145
+ // dataBMap.set(k, v);
146
+ if ([undefined, null].includes(dataAllMap.get(k))) {
147
+ dataAllMap.set(k, v);
148
+ }
149
+ });
150
+ var newData = {};
151
+ dataAllMap.forEach(function (v, k) {
152
+ newData[k] = v;
153
+ });
154
+ return newData;
155
+ }
156
+ ObjectUtil.mergeParams = mergeParams;
157
+ })(ObjectUtil || (ObjectUtil = {}));
158
+ export default ObjectUtil;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 加密工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 14:23:42
6
+ */
7
+ declare namespace PasswordUtil {
8
+ /**
9
+ * AES加密函数
10
+ * @param str 待加密字符串
11
+ * @param pwd 加密密钥
12
+ * @example
13
+ * strEncrypt('XX') => 3f231e9c5040a51a663a4e12ddd509fc31f201caf95f
14
+ */
15
+ const strEncrypt: (str: string, pwd?: string) => any;
16
+ /**
17
+ * AES解密函数
18
+ * @param str 待解密字符串
19
+ * @param pwd 解密密钥
20
+ * @example
21
+ * strDecrypt('3f231e9c5040a51a663a4e12ddd509fc31f201caf95f') => XX
22
+ */
23
+ const strDecrypt: (str: string, pwd?: string) => any;
24
+ /**
25
+ * MD5加密函数
26
+ * @param str 待加密字符串
27
+ * @param pwd 加密密钥
28
+ * @example
29
+ * str2MD5('1111') => ea69274f6555a750bec9985a07f80455
30
+ */
31
+ const str2MD5: (str: string, pwd?: string) => any;
32
+ }
33
+ export default PasswordUtil;
@@ -0,0 +1,68 @@
1
+ import config from '../config';
2
+ import crypto from './crypto';
3
+ var CryptoJS = crypto();
4
+ /**
5
+ * 加密工具
6
+ * @description
7
+ * @author nanshen
8
+ * @creat 2021-09-15 14:23:42
9
+ */
10
+ var PasswordUtil;
11
+ (function (PasswordUtil) {
12
+ var defaultPwd = config.aesKey;
13
+ var defaultMD5Key = config.md5Key;
14
+ /**
15
+ * AES加密函数
16
+ * @param str 待加密字符串
17
+ * @param pwd 加密密钥
18
+ * @example
19
+ * strEncrypt('XX') => 3f231e9c5040a51a663a4e12ddd509fc31f201caf95f
20
+ */
21
+ PasswordUtil.strEncrypt = function (str, pwd) {
22
+ if (pwd === void 0) {
23
+ pwd = defaultPwd;
24
+ }
25
+ if (!str) return '';
26
+ var key = CryptoJS.enc.Utf8.parse(pwd);
27
+ var srcs = CryptoJS.enc.Utf8.parse(str);
28
+ var encrypted = CryptoJS.AES.encrypt(srcs, key, {
29
+ mode: CryptoJS.mode.ECB,
30
+ padding: CryptoJS.pad.Pkcs7
31
+ });
32
+ return encrypted.toString();
33
+ };
34
+ /**
35
+ * AES解密函数
36
+ * @param str 待解密字符串
37
+ * @param pwd 解密密钥
38
+ * @example
39
+ * strDecrypt('3f231e9c5040a51a663a4e12ddd509fc31f201caf95f') => XX
40
+ */
41
+ PasswordUtil.strDecrypt = function (str, pwd) {
42
+ if (pwd === void 0) {
43
+ pwd = defaultPwd;
44
+ }
45
+ if (str == '') return '';
46
+ var key = CryptoJS.enc.Utf8.parse(pwd);
47
+ var decrypt = CryptoJS.AES.decrypt(str, key, {
48
+ mode: CryptoJS.mode.ECB,
49
+ padding: CryptoJS.pad.Pkcs7
50
+ });
51
+ return CryptoJS.enc.Utf8.stringify(decrypt).toString();
52
+ };
53
+ /**
54
+ * MD5加密函数
55
+ * @param str 待加密字符串
56
+ * @param pwd 加密密钥
57
+ * @example
58
+ * str2MD5('1111') => ea69274f6555a750bec9985a07f80455
59
+ */
60
+ PasswordUtil.str2MD5 = function (str, pwd) {
61
+ if (pwd === void 0) {
62
+ pwd = defaultMD5Key;
63
+ }
64
+ if (!str) return '';
65
+ return CryptoJS.MD5(pwd + str).toString();
66
+ };
67
+ })(PasswordUtil || (PasswordUtil = {}));
68
+ export default PasswordUtil;
@@ -0,0 +1,6 @@
1
+ export default cryptoFn;
2
+ declare function cryptoFn(): {
3
+ lib: {};
4
+ enc: {};
5
+ algo: {};
6
+ };