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,323 @@
1
+ /**
2
+ * 转化工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 14:40:07
6
+ */
7
+ import BaseUtil from "../base/BaseUtil";
8
+ var TransferUtil;
9
+ (function (TransferUtil) {
10
+ /**
11
+ * 字符串转成base64编码
12
+ * @param { String } str 字符串
13
+ * @example
14
+ * base64Encode('nanshen') => bmFuc2hlbg==
15
+ */
16
+ function base64Encode(str) {
17
+ return window.btoa(str);
18
+ }
19
+ TransferUtil.base64Encode = base64Encode;
20
+ /**
21
+ * base64解码成字符串
22
+ * @param { String } str base64字符串
23
+ * @example
24
+ * base64Decode('bmFuc2hlbg==') => nanshen
25
+ */
26
+ function base64Decode(str) {
27
+ return window.atob(decodeURIComponent(str));
28
+ }
29
+ TransferUtil.base64Decode = base64Decode;
30
+ /**
31
+ * 将文件转成base64
32
+ * @param file 文件
33
+ * @example
34
+ * const fn = async () => {
35
+ * const newFile = new File(['text1', 'text2'], 'test.txt', {type: 'text/plain'})
36
+ * const data = await getBase64ByFile(newFile)
37
+ * console.log(data); => data:text/plain;base64,dGV4dDF0ZXh0Mg==
38
+ * }
39
+ * fn()
40
+ */
41
+ function getBase64ByFile(file) {
42
+ if (BaseUtil.isEmpty(file)) return undefined;
43
+ return new Promise(function (resolve, reject) {
44
+ var reader = new FileReader();
45
+ var imgResult = "";
46
+ reader.readAsDataURL(file);
47
+ reader.onload = function () {
48
+ imgResult = reader.result;
49
+ };
50
+ reader.onerror = function (error) {
51
+ reject(error);
52
+ };
53
+ reader.onloadend = function () {
54
+ resolve(imgResult);
55
+ };
56
+ });
57
+ }
58
+ TransferUtil.getBase64ByFile = getBase64ByFile;
59
+ /**
60
+ * 将base64转成文件
61
+ * @param file 文件
62
+ * @example
63
+ * getFileByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==','test.txt') => new File(['text1', 'text2'], 'test.txt', {type: 'text/plain'})
64
+ */
65
+ function getFileByBase64(base64, filename) {
66
+ var _a, _b;
67
+ if (BaseUtil.isEmpty(base64)) return undefined;
68
+ var arr = base64.split(","),
69
+ mime = (_b = (_a = arr === null || arr === void 0 ? void 0 : arr[0]) === null || _a === void 0 ? void 0 : _a.match(/:(.*?);/)) === null || _b === void 0 ? void 0 : _b[1],
70
+ bstr = window.atob(arr[1]),
71
+ n = bstr.length,
72
+ u8arr = new Uint8Array(n);
73
+ while (n--) {
74
+ u8arr[n] = bstr.charCodeAt(n);
75
+ }
76
+ return new File([u8arr], filename, {
77
+ type: mime
78
+ });
79
+ }
80
+ TransferUtil.getFileByBase64 = getFileByBase64;
81
+ /**
82
+ * base64转blob流
83
+ * @param base64 base64字符串
84
+ * @example
85
+ * getBlobByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==') => new Blob(['text1', 'text2'], {type : 'text/plain'})
86
+ */
87
+ function getBlobByBase64(base64) {
88
+ var _a, _b, _c;
89
+ if (BaseUtil.isEmpty(base64)) return undefined;
90
+ var byteString;
91
+ if (((_b = (_a = base64 === null || base64 === void 0 ? void 0 : base64.split(",")) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.indexOf("base64")) >= 0) byteString = atob(base64.split(",")[1]);
92
+ //base64 解码
93
+ else {
94
+ byteString = unescape((_c = base64.split(",")) === null || _c === void 0 ? void 0 : _c[1]);
95
+ }
96
+ var mimeString = base64.split(",")[0].split(":")[1].split(";")[0]; //mime类型 -- image/png
97
+ var ia = new Uint8Array(byteString.length); //创建视图
98
+ for (var i = 0; i < byteString.length; i++) {
99
+ ia[i] = byteString.charCodeAt(i);
100
+ }
101
+ var blob = new Blob([ia], {
102
+ type: mimeString
103
+ });
104
+ return blob;
105
+ }
106
+ TransferUtil.getBlobByBase64 = getBlobByBase64;
107
+ /**
108
+ * blob流转换为base64
109
+ * @param blob blob流
110
+ * @example
111
+ * const fn = async () => {
112
+ * const newBlob = new Blob(['text1', 'text2'], {type : 'text/plain'})
113
+ * const data = await blobToDataURI(newBlob)
114
+ * console.log(data); => data:text/plain;base64,dGV4dDF0ZXh0Mg==
115
+ * }
116
+ * fn()
117
+ */
118
+ function blobToDataURI(blob) {
119
+ if (BaseUtil.isEmpty(blob)) return undefined;
120
+ return new Promise(function (resolve, reject) {
121
+ var reader = new FileReader();
122
+ reader.readAsDataURL(blob);
123
+ var imgResult = "";
124
+ reader.onload = function (e) {
125
+ var _a;
126
+ imgResult = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.result;
127
+ };
128
+ reader.onerror = function (error) {
129
+ reject(error);
130
+ };
131
+ reader.onloadend = function () {
132
+ resolve(imgResult);
133
+ };
134
+ });
135
+ }
136
+ TransferUtil.blobToDataURI = blobToDataURI;
137
+ /**
138
+ * html编码(转义)
139
+ * @param { String } text 需要转义的字符串
140
+ * @param { Boolean } useDom 转换方法选择
141
+ * @example
142
+ * htmlEncode('<p>你好</p>') => &lt;p&gt;你好&lt;/p&gt;
143
+ */
144
+ function htmlEncode(text, useDom) {
145
+ if (useDom === void 0) {
146
+ useDom = false;
147
+ }
148
+ if (BaseUtil.isEmpty(text)) return "";
149
+ var output = "";
150
+ if (useDom) {
151
+ var el = document.createElement("div");
152
+ el.textContent !== undefined ? el.textContent = text : el.innerText = text;
153
+ output = el.innerHTML;
154
+ el = null;
155
+ } else {
156
+ output = text.replace(/&/g, "&amp;");
157
+ output = output.replace(/</g, "&lt;");
158
+ output = output.replace(/>/g, "&gt;");
159
+ output = output.replace(/\s/g, "&nbsp;");
160
+ output = output.replace(/\\'/g, "&#39;");
161
+ output = output.replace(/\\"/g, "&quot;");
162
+ }
163
+ return output;
164
+ }
165
+ TransferUtil.htmlEncode = htmlEncode;
166
+ /**
167
+ * html解码(反转义)
168
+ * @param { String } text 需要反转义的字符串
169
+ * @param { Boolean } useDom 转换方法选择
170
+ * @example
171
+ * htmlDecode('&lt;p&gt;你好&lt;/p&gt') => <p>你好</p>
172
+ */
173
+ function htmlDecode(text, useDom) {
174
+ if (useDom === void 0) {
175
+ useDom = false;
176
+ }
177
+ if (BaseUtil.isEmpty(text)) return "";
178
+ var output = "";
179
+ if (useDom) {
180
+ var el = document.createElement("div");
181
+ el.innerHTML = text;
182
+ output = (el === null || el === void 0 ? void 0 : el.innerText) || (el === null || el === void 0 ? void 0 : el.textContent) || "";
183
+ el = null;
184
+ } else {
185
+ output = text.replace(/&amp;/g, "&");
186
+ output = output.replace(/&lt;/g, "<");
187
+ output = output.replace(/&gt;/g, ">");
188
+ output = output.replace(/&nbsp;/g, " ");
189
+ output = output.replace(/&#39;/g, "'");
190
+ output = output.replace(/&quot;/g, '"');
191
+ }
192
+ return output;
193
+ }
194
+ TransferUtil.htmlDecode = htmlDecode;
195
+ /**
196
+ * 现金额转大写
197
+ * @param n 阿拉伯数字
198
+ * @example
199
+ * digitUppercase(1) => 壹元整
200
+ */
201
+ function digitUppercase(n) {
202
+ var fraction = ["角", "分"];
203
+ var digit = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
204
+ var unit = [["元", "万", "亿"], ["", "拾", "佰", "仟"]];
205
+ var head = n < 0 ? "欠" : "";
206
+ n = Math.abs(n);
207
+ var s = "";
208
+ for (var i = 0; i < fraction.length; i++) {
209
+ s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, "");
210
+ }
211
+ s = s || "整";
212
+ n = Math.floor(n);
213
+ for (var i = 0; i < unit[0].length && n > 0; i++) {
214
+ var p = "";
215
+ for (var j = 0; j < unit[1].length && n > 0; j++) {
216
+ p = digit[n % 10] + unit[1][j] + p;
217
+ n = Math.floor(n / 10);
218
+ }
219
+ s = p.replace(/(零.)*零$/, "").replace(/^$/, "零") + unit[0][i] + s;
220
+ }
221
+ return head + s.replace(/(零.)*零元/, "元").replace(/(零.)+/g, "零").replace(/^整$/, "零元整");
222
+ }
223
+ TransferUtil.digitUppercase = digitUppercase;
224
+ /**
225
+ * 数字转大写
226
+ * @param n 阿拉伯数字
227
+ * @example
228
+ * digitUppercase(1) => 一
229
+ */
230
+ function toChinesNum(num) {
231
+ var changeNum = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"]; //changeNum[0] = "零"
232
+ var unit = ["", "十", "百", "千", "万"];
233
+ num = parseInt("".concat(num));
234
+ var getWan = function getWan(temp) {
235
+ var _a, _b;
236
+ var strArr = (_b = (_a = "".concat(temp)) === null || _a === void 0 ? void 0 : _a.split("")) === null || _b === void 0 ? void 0 : _b.reverse();
237
+ var newNum = "";
238
+ for (var i = 0; i < strArr.length; i++) {
239
+ newNum = (i == 0 && (strArr === null || strArr === void 0 ? void 0 : strArr[i]) === 0 ? "" : i > 0 && (strArr === null || strArr === void 0 ? void 0 : strArr[i]) === 0 && (strArr === null || strArr === void 0 ? void 0 : strArr[i - 1]) === 0 ? "" : changeNum[strArr[i]] + ((strArr === null || strArr === void 0 ? void 0 : strArr[i]) == 0 ? unit[0] : unit[i])) + newNum;
240
+ }
241
+ return newNum;
242
+ };
243
+ var overWan = Math.floor(num / 10000);
244
+ var noWan = num % 10000;
245
+ if (noWan.toString().length < 4) noWan = "0" + noWan;
246
+ return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
247
+ }
248
+ TransferUtil.toChinesNum = toChinesNum;
249
+ /**
250
+ * 数字大于千万亿加单位
251
+ * @param value 阿拉伯数字
252
+ * @param index 保留几位小数(默认为2)
253
+ * @example
254
+ * numPlusUnit(1213) => 1.21千
255
+ */
256
+ function numPlusUnit(value, index) {
257
+ if (index === void 0) {
258
+ index = 2;
259
+ }
260
+ if (!/^(0|[1-9]\d*)(\.\d+)?$/.test("".concat(value))) {
261
+ return "暂无数据"; //暂无数据
262
+ }
263
+ var newValue = ["", "", ""];
264
+ var fr = 1000;
265
+ var num = 3;
266
+ while (value / fr >= 1) {
267
+ fr *= 10;
268
+ num += 1;
269
+ }
270
+ if (num <= 4) {
271
+ // 千
272
+ newValue[1] = "千";
273
+ newValue[0] = (value / 1000).toFixed(index);
274
+ } else if (num <= 8) {
275
+ // 万
276
+ var text1 = parseInt("".concat(num - 4)) / 3 > 1 ? "千万" : "万";
277
+ // tslint:disable-next-line:no-shadowed-variable
278
+ var fm = "万" === text1 ? 10000 : 10000000;
279
+ newValue[1] = text1;
280
+ newValue[0] = (value / fm).toFixed(index);
281
+ } else if (num <= 16) {
282
+ // 亿
283
+ var text1 = (num - 8) / 3 > 1 ? "千亿" : "亿";
284
+ text1 = (num - 8) / 4 > 1 ? "万亿" : text1;
285
+ text1 = (num - 8) / 7 > 1 ? "千万亿" : text1;
286
+ // tslint:disable-next-line:no-shadowed-variable
287
+ var fm = 1;
288
+ if ("亿" === text1) {
289
+ fm = 100000000;
290
+ } else if ("千亿" === text1) {
291
+ fm = 100000000000;
292
+ } else if ("万亿" === text1) {
293
+ fm = 1000000000000;
294
+ } else if ("千万亿" === text1) {
295
+ fm = 1000000000000000;
296
+ }
297
+ newValue[1] = text1;
298
+ newValue[0] = (value / fm).toFixed(index);
299
+ }
300
+ if (value < 1000) {
301
+ newValue[1] = "";
302
+ newValue[0] = "".concat(value);
303
+ }
304
+ return newValue.join("");
305
+ }
306
+ TransferUtil.numPlusUnit = numPlusUnit;
307
+ /**
308
+ * 字节转单位
309
+ * @param bytes - 字节
310
+ */
311
+ TransferUtil.getFileSizeByBytes = function (bytes) {
312
+ var sizes = ["B", "KB", "MB", "GB", "TB"];
313
+ if (bytes === 0) {
314
+ return "0B";
315
+ }
316
+ var i = Math.floor(Math.log(bytes) / Math.log(1024));
317
+ if (i === 0) {
318
+ return bytes + sizes[i];
319
+ }
320
+ return (bytes / Math.pow(1024, i)).toFixed(2) + sizes[i];
321
+ };
322
+ })(TransferUtil || (TransferUtil = {}));
323
+ export default TransferUtil;
package/esm/types.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export type ValueType = string | number;
2
+ export type TreeData = {
3
+ key: string;
4
+ title: string;
5
+ };
6
+ /** @name 缓存配置 */
7
+ export type SessionOpts = {
8
+ /** @name 窗口缓存|永久缓存 */
9
+ type?: "session" | "local";
10
+ /** @name 缓存全名,优先级高于全局 */
11
+ itemName?: string;
12
+ };
13
+ /** @name 树对象的字段映射 默认值{ label = "name", value = "id", parent = "pid", children = "children", rootPid = null } */
14
+ export type FieldNames = {
15
+ /** @name 显示的字段 */
16
+ label?: string;
17
+ /** @name 主键字段 */
18
+ value?: string;
19
+ /** @name 父主键字段 */
20
+ parent?: string;
21
+ /** @name 子数组字段 */
22
+ children?: string;
23
+ /** @name 根节点的值 */
24
+ rootPid?: any;
25
+ };
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ declare namespace UrlUtil {
2
+ /**
3
+ * 把对象格式的参数转成键值对,并以&连接
4
+ * @param { Object } obj 对象
5
+ * @example
6
+ * objToUrlParam({a:213,b:2131}) => "a=213&b=2131"
7
+ */
8
+ function objToUrlParam(obj: Record<any, any>): string;
9
+ /**
10
+ * 移除url的某一个参数
11
+ * @param { Array } paramNames 参数名称的数组
12
+ * @param { URL } url url地址
13
+ * @example
14
+ * deleteUrlParam(['a'],'http:XXX.cn?a=12&b=sad') => "http:XXX.cn?b=sad"
15
+ */
16
+ function deleteUrlParam(paramNames: string[], url?: string): string;
17
+ /**
18
+ * 解析url参数
19
+ * @param href url地址
20
+ * @example
21
+ * getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
22
+ */
23
+ const getUrlRequest: (href?: string) => Record<any, any>;
24
+ /**
25
+ * 不刷新改变url参数
26
+ * @param obj 对象
27
+ */
28
+ function setUrlParamsNotRefresh(obj: Record<any, any>): void;
29
+ }
30
+ export default UrlUtil;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * url工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 14:40:22
6
+ */
7
+ import BaseUtil from '../base/BaseUtil';
8
+ import ObjectUtil from '../object/ObjectUtil';
9
+ var UrlUtil;
10
+ (function (UrlUtil) {
11
+ /**
12
+ * 把对象格式的参数转成键值对,并以&连接
13
+ * @param { Object } obj 对象
14
+ * @example
15
+ * objToUrlParam({a:213,b:2131}) => "a=213&b=2131"
16
+ */
17
+ function objToUrlParam(obj) {
18
+ if (BaseUtil.isEmpty(obj)) return '';
19
+ var result = '';
20
+ for (var key in obj) {
21
+ result += "".concat(key, "=").concat(encodeURIComponent(obj[key]), "&");
22
+ }
23
+ result = result.substr(0, result.length - 1);
24
+ return result;
25
+ }
26
+ UrlUtil.objToUrlParam = objToUrlParam;
27
+ /**
28
+ * 移除url的某一个参数
29
+ * @param { Array } paramNames 参数名称的数组
30
+ * @param { URL } url url地址
31
+ * @example
32
+ * deleteUrlParam(['a'],'http:XXX.cn?a=12&b=sad') => "http:XXX.cn?b=sad"
33
+ */
34
+ function deleteUrlParam(paramNames, url) {
35
+ var _a, _b;
36
+ if (url === void 0) {
37
+ url = location.href;
38
+ }
39
+ var newSearch = (_a = url === null || url === void 0 ? void 0 : url.split('?')) === null || _a === void 0 ? void 0 : _a[1];
40
+ if (!newSearch) return url;
41
+ var hostAndPath = (_b = url === null || url === void 0 ? void 0 : url.split('?')) === null || _b === void 0 ? void 0 : _b[0];
42
+ var urlSearch = new URLSearchParams(newSearch);
43
+ paramNames.forEach(function (param) {
44
+ var _a;
45
+ (_a = urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch['delete']) === null || _a === void 0 ? void 0 : _a.call(urlSearch, param);
46
+ });
47
+ return (urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch.toString()) ? "".concat(hostAndPath, "?").concat(urlSearch.toString()) : hostAndPath;
48
+ }
49
+ UrlUtil.deleteUrlParam = deleteUrlParam;
50
+ /**
51
+ * 解析url参数
52
+ * @param href url地址
53
+ * @example
54
+ * getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
55
+ */
56
+ UrlUtil.getUrlRequest = function (href) {
57
+ if (href === void 0) {
58
+ href = window.location.href;
59
+ }
60
+ var url = href === null || href === void 0 ? void 0 : href.slice(href === null || href === void 0 ? void 0 : href.indexOf('?'));
61
+ var theRequest = {};
62
+ if (url.indexOf('?') !== -1) {
63
+ var str = url.substr(1);
64
+ var strs = str.split('&');
65
+ for (var i = 0; i < strs.length; i++) {
66
+ theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]).replaceAll('#/', '');
67
+ }
68
+ }
69
+ return theRequest;
70
+ };
71
+ /**
72
+ * 不刷新改变url参数
73
+ * @param obj 对象
74
+ */
75
+ function setUrlParamsNotRefresh(obj) {
76
+ var urlParams = UrlUtil.getUrlRequest();
77
+ var str = objToUrlParam(ObjectUtil.mergeParams(obj, urlParams));
78
+ var url = "".concat(window.location.href.split('?')[0]).concat(str ? "?".concat(str) : '');
79
+ window.history.replaceState({
80
+ url: url
81
+ }, '', url);
82
+ }
83
+ UrlUtil.setUrlParamsNotRefresh = setUrlParamsNotRefresh;
84
+ })(UrlUtil || (UrlUtil = {}));
85
+ export default UrlUtil;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * 数组工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 10:31:35
6
+ */
7
+ declare namespace ArrayUtil {
8
+ /**
9
+ * 对象数组去重
10
+ * @param array 去重对象
11
+ * @param key 去重key
12
+ * @param isSaveLast 默认true ,true返回重复最后一个对象,false返回重复第一个对象
13
+ * @example
14
+ * const array = [{a:1,b:3},{a:1,b:2},{a:2,b:1}]
15
+ * arrayWeightRemoval(array,'a',true) => [{a:1,b:2},{a:2,b:1}]
16
+ * arrayWeightRemoval(array,'a',false) => [{a:1,b:3},{a:2,b:1}]
17
+ */
18
+ const arrayWeightRemoval: <T, U>(array: T[] | undefined, key: U extends keyof T ? U : undefined, isSaveLast?: boolean) => T[];
19
+ /**
20
+ * 数组去重
21
+ * @param { (number | string)[]} arr 数组
22
+ * @example
23
+ * unique([1,3,1]) =>[1,3]
24
+ */
25
+ const unique: (arr: (number | string)[]) => (number | string)[];
26
+ /**
27
+ * 求两个集合的并集
28
+ * @param { (number | string)[]} a 集合a
29
+ * @param { (number | string)[]} b 集合b
30
+ * @example
31
+ * union([1,3,4],[1,2]) => [1,2,3,4]
32
+ */
33
+ const union: (a: (number | string)[], b: (number | string)[]) => (number | string)[];
34
+ /**
35
+ * 求两个集合的交集
36
+ * @param { (number | string)[]} a 集合a
37
+ * @param { (number | string)[]} b 集合b
38
+ * @example
39
+ * intersect([1,3,4],[1,2]) => [1]
40
+ */
41
+ const intersect: (a: (number | string)[], b: (number | string)[]) => (number | string)[];
42
+ /**
43
+ * 求两个集合的差集
44
+ * @param { (number | string)[]} a 集合a
45
+ * @param { (number | string)[]} b 集合b
46
+ * @example
47
+ * difference([1,2,3],[1]) => [2,3]
48
+ */
49
+ const difference: (a: (number | string)[], b: (number | string)[]) => (number | string)[];
50
+ /**
51
+ * 最大值
52
+ * @param {number[]} arr 数组
53
+ * @example
54
+ * max([1,2,3]) => 3
55
+ */
56
+ const max: (arr: number[]) => number;
57
+ /**
58
+ * 最小值
59
+ * @export
60
+ * @param {number[]} arr 数组
61
+ * @example
62
+ * min([1,2,3]) => 1
63
+ */
64
+ const min: (arr: number[]) => number;
65
+ /**
66
+ * 求和
67
+ * @export
68
+ * @param {number[]} arr 数字数组
69
+ * @example
70
+ * sum([1,2]) => 3
71
+ */
72
+ const sum: (arr: number[]) => number;
73
+ /**
74
+ * 平均值
75
+ * @export
76
+ * @param {number[]} arr 数字数组
77
+ * @example
78
+ * average([1,2,3]) => 2
79
+ */
80
+ const average: (arr: number[]) => number;
81
+ /**
82
+ * 删除其中一个元素
83
+ * @export
84
+ * @param {(number | string)[]} arr 数组
85
+ * @param {(number | string)} ele 要删除的元素
86
+ * @example
87
+ * remove([1,2,3],3) => [1,2]
88
+ */
89
+ const remove: (arr: (number | string)[], ele: number | string) => (number | string)[];
90
+ /**
91
+ * 数组排序
92
+ * @param {number[]} arr 数组
93
+ * @param {number} type 1:从小到大 2:从大到小 3:随机
94
+ * @example
95
+ * sort([1,2,3],1) => [1,2,3]
96
+ * sort([1,2,3],2) => [3,2,1]
97
+ * sort([1,2,3],3) => [1,3,2]
98
+ */
99
+ const sort: (arr: number[], type?: number) => number[];
100
+ /**
101
+ * 随机排序数组
102
+ * @param arr any[]
103
+ * @example
104
+ * randomSortArr([1,2,3]) => [1,3,2]
105
+ * randomSortArr([{a:1},{a:2},{a:3}]) => [{a:3},{a:1},{a:2}]
106
+ */
107
+ function randomSortArr<T>(arr: T[]): T[];
108
+ }
109
+ export default ArrayUtil;