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,333 @@
1
+ "use strict";
2
+
3
+ var __importDefault = this && this.__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ /**
12
+ * 转化工具
13
+ * @description
14
+ * @author nanshen
15
+ * @creat 2021-09-15 14:40:07
16
+ */
17
+ var BaseUtil_1 = __importDefault(require("../base/BaseUtil"));
18
+ var TransferUtil;
19
+ (function (TransferUtil) {
20
+ /**
21
+ * 字符串转成base64编码
22
+ * @param { String } str 字符串
23
+ * @example
24
+ * base64Encode('nanshen') => bmFuc2hlbg==
25
+ */
26
+ function base64Encode(str) {
27
+ return window.btoa(str);
28
+ }
29
+ TransferUtil.base64Encode = base64Encode;
30
+ /**
31
+ * base64解码成字符串
32
+ * @param { String } str base64字符串
33
+ * @example
34
+ * base64Decode('bmFuc2hlbg==') => nanshen
35
+ */
36
+ function base64Decode(str) {
37
+ return window.atob(decodeURIComponent(str));
38
+ }
39
+ TransferUtil.base64Decode = base64Decode;
40
+ /**
41
+ * 将文件转成base64
42
+ * @param file 文件
43
+ * @example
44
+ * const fn = async () => {
45
+ * const newFile = new File(['text1', 'text2'], 'test.txt', {type: 'text/plain'})
46
+ * const data = await getBase64ByFile(newFile)
47
+ * console.log(data); => data:text/plain;base64,dGV4dDF0ZXh0Mg==
48
+ * }
49
+ * fn()
50
+ */
51
+ function getBase64ByFile(file) {
52
+ if (BaseUtil_1.default.isEmpty(file)) return undefined;
53
+ return new Promise(function (resolve, reject) {
54
+ var reader = new FileReader();
55
+ var imgResult = "";
56
+ reader.readAsDataURL(file);
57
+ reader.onload = function () {
58
+ imgResult = reader.result;
59
+ };
60
+ reader.onerror = function (error) {
61
+ reject(error);
62
+ };
63
+ reader.onloadend = function () {
64
+ resolve(imgResult);
65
+ };
66
+ });
67
+ }
68
+ TransferUtil.getBase64ByFile = getBase64ByFile;
69
+ /**
70
+ * 将base64转成文件
71
+ * @param file 文件
72
+ * @example
73
+ * getFileByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==','test.txt') => new File(['text1', 'text2'], 'test.txt', {type: 'text/plain'})
74
+ */
75
+ function getFileByBase64(base64, filename) {
76
+ var _a, _b;
77
+ if (BaseUtil_1.default.isEmpty(base64)) return undefined;
78
+ var arr = base64.split(","),
79
+ 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],
80
+ bstr = window.atob(arr[1]),
81
+ n = bstr.length,
82
+ u8arr = new Uint8Array(n);
83
+ while (n--) {
84
+ u8arr[n] = bstr.charCodeAt(n);
85
+ }
86
+ return new File([u8arr], filename, {
87
+ type: mime
88
+ });
89
+ }
90
+ TransferUtil.getFileByBase64 = getFileByBase64;
91
+ /**
92
+ * base64转blob流
93
+ * @param base64 base64字符串
94
+ * @example
95
+ * getBlobByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==') => new Blob(['text1', 'text2'], {type : 'text/plain'})
96
+ */
97
+ function getBlobByBase64(base64) {
98
+ var _a, _b, _c;
99
+ if (BaseUtil_1.default.isEmpty(base64)) return undefined;
100
+ var byteString;
101
+ 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]);
102
+ //base64 解码
103
+ else {
104
+ byteString = unescape((_c = base64.split(",")) === null || _c === void 0 ? void 0 : _c[1]);
105
+ }
106
+ var mimeString = base64.split(",")[0].split(":")[1].split(";")[0]; //mime类型 -- image/png
107
+ var ia = new Uint8Array(byteString.length); //创建视图
108
+ for (var i = 0; i < byteString.length; i++) {
109
+ ia[i] = byteString.charCodeAt(i);
110
+ }
111
+ var blob = new Blob([ia], {
112
+ type: mimeString
113
+ });
114
+ return blob;
115
+ }
116
+ TransferUtil.getBlobByBase64 = getBlobByBase64;
117
+ /**
118
+ * blob流转换为base64
119
+ * @param blob blob流
120
+ * @example
121
+ * const fn = async () => {
122
+ * const newBlob = new Blob(['text1', 'text2'], {type : 'text/plain'})
123
+ * const data = await blobToDataURI(newBlob)
124
+ * console.log(data); => data:text/plain;base64,dGV4dDF0ZXh0Mg==
125
+ * }
126
+ * fn()
127
+ */
128
+ function blobToDataURI(blob) {
129
+ if (BaseUtil_1.default.isEmpty(blob)) return undefined;
130
+ return new Promise(function (resolve, reject) {
131
+ var reader = new FileReader();
132
+ reader.readAsDataURL(blob);
133
+ var imgResult = "";
134
+ reader.onload = function (e) {
135
+ var _a;
136
+ imgResult = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.result;
137
+ };
138
+ reader.onerror = function (error) {
139
+ reject(error);
140
+ };
141
+ reader.onloadend = function () {
142
+ resolve(imgResult);
143
+ };
144
+ });
145
+ }
146
+ TransferUtil.blobToDataURI = blobToDataURI;
147
+ /**
148
+ * html编码(转义)
149
+ * @param { String } text 需要转义的字符串
150
+ * @param { Boolean } useDom 转换方法选择
151
+ * @example
152
+ * htmlEncode('<p>你好</p>') => &lt;p&gt;你好&lt;/p&gt;
153
+ */
154
+ function htmlEncode(text, useDom) {
155
+ if (useDom === void 0) {
156
+ useDom = false;
157
+ }
158
+ if (BaseUtil_1.default.isEmpty(text)) return "";
159
+ var output = "";
160
+ if (useDom) {
161
+ var el = document.createElement("div");
162
+ el.textContent !== undefined ? el.textContent = text : el.innerText = text;
163
+ output = el.innerHTML;
164
+ el = null;
165
+ } else {
166
+ output = text.replace(/&/g, "&amp;");
167
+ output = output.replace(/</g, "&lt;");
168
+ output = output.replace(/>/g, "&gt;");
169
+ output = output.replace(/\s/g, "&nbsp;");
170
+ output = output.replace(/\\'/g, "&#39;");
171
+ output = output.replace(/\\"/g, "&quot;");
172
+ }
173
+ return output;
174
+ }
175
+ TransferUtil.htmlEncode = htmlEncode;
176
+ /**
177
+ * html解码(反转义)
178
+ * @param { String } text 需要反转义的字符串
179
+ * @param { Boolean } useDom 转换方法选择
180
+ * @example
181
+ * htmlDecode('&lt;p&gt;你好&lt;/p&gt') => <p>你好</p>
182
+ */
183
+ function htmlDecode(text, useDom) {
184
+ if (useDom === void 0) {
185
+ useDom = false;
186
+ }
187
+ if (BaseUtil_1.default.isEmpty(text)) return "";
188
+ var output = "";
189
+ if (useDom) {
190
+ var el = document.createElement("div");
191
+ el.innerHTML = text;
192
+ output = (el === null || el === void 0 ? void 0 : el.innerText) || (el === null || el === void 0 ? void 0 : el.textContent) || "";
193
+ el = null;
194
+ } else {
195
+ output = text.replace(/&amp;/g, "&");
196
+ output = output.replace(/&lt;/g, "<");
197
+ output = output.replace(/&gt;/g, ">");
198
+ output = output.replace(/&nbsp;/g, " ");
199
+ output = output.replace(/&#39;/g, "'");
200
+ output = output.replace(/&quot;/g, '"');
201
+ }
202
+ return output;
203
+ }
204
+ TransferUtil.htmlDecode = htmlDecode;
205
+ /**
206
+ * 现金额转大写
207
+ * @param n 阿拉伯数字
208
+ * @example
209
+ * digitUppercase(1) => 壹元整
210
+ */
211
+ function digitUppercase(n) {
212
+ var fraction = ["角", "分"];
213
+ var digit = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
214
+ var unit = [["元", "万", "亿"], ["", "拾", "佰", "仟"]];
215
+ var head = n < 0 ? "欠" : "";
216
+ n = Math.abs(n);
217
+ var s = "";
218
+ for (var i = 0; i < fraction.length; i++) {
219
+ s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, "");
220
+ }
221
+ s = s || "整";
222
+ n = Math.floor(n);
223
+ for (var i = 0; i < unit[0].length && n > 0; i++) {
224
+ var p = "";
225
+ for (var j = 0; j < unit[1].length && n > 0; j++) {
226
+ p = digit[n % 10] + unit[1][j] + p;
227
+ n = Math.floor(n / 10);
228
+ }
229
+ s = p.replace(/(零.)*零$/, "").replace(/^$/, "零") + unit[0][i] + s;
230
+ }
231
+ return head + s.replace(/(零.)*零元/, "元").replace(/(零.)+/g, "零").replace(/^整$/, "零元整");
232
+ }
233
+ TransferUtil.digitUppercase = digitUppercase;
234
+ /**
235
+ * 数字转大写
236
+ * @param n 阿拉伯数字
237
+ * @example
238
+ * digitUppercase(1) => 一
239
+ */
240
+ function toChinesNum(num) {
241
+ var changeNum = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"]; //changeNum[0] = "零"
242
+ var unit = ["", "十", "百", "千", "万"];
243
+ num = parseInt("".concat(num));
244
+ var getWan = function getWan(temp) {
245
+ var _a, _b;
246
+ var strArr = (_b = (_a = "".concat(temp)) === null || _a === void 0 ? void 0 : _a.split("")) === null || _b === void 0 ? void 0 : _b.reverse();
247
+ var newNum = "";
248
+ for (var i = 0; i < strArr.length; i++) {
249
+ 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;
250
+ }
251
+ return newNum;
252
+ };
253
+ var overWan = Math.floor(num / 10000);
254
+ var noWan = num % 10000;
255
+ if (noWan.toString().length < 4) noWan = "0" + noWan;
256
+ return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
257
+ }
258
+ TransferUtil.toChinesNum = toChinesNum;
259
+ /**
260
+ * 数字大于千万亿加单位
261
+ * @param value 阿拉伯数字
262
+ * @param index 保留几位小数(默认为2)
263
+ * @example
264
+ * numPlusUnit(1213) => 1.21千
265
+ */
266
+ function numPlusUnit(value, index) {
267
+ if (index === void 0) {
268
+ index = 2;
269
+ }
270
+ if (!/^(0|[1-9]\d*)(\.\d+)?$/.test("".concat(value))) {
271
+ return "暂无数据"; //暂无数据
272
+ }
273
+ var newValue = ["", "", ""];
274
+ var fr = 1000;
275
+ var num = 3;
276
+ while (value / fr >= 1) {
277
+ fr *= 10;
278
+ num += 1;
279
+ }
280
+ if (num <= 4) {
281
+ // 千
282
+ newValue[1] = "千";
283
+ newValue[0] = (value / 1000).toFixed(index);
284
+ } else if (num <= 8) {
285
+ // 万
286
+ var text1 = parseInt("".concat(num - 4)) / 3 > 1 ? "千万" : "万";
287
+ // tslint:disable-next-line:no-shadowed-variable
288
+ var fm = "万" === text1 ? 10000 : 10000000;
289
+ newValue[1] = text1;
290
+ newValue[0] = (value / fm).toFixed(index);
291
+ } else if (num <= 16) {
292
+ // 亿
293
+ var text1 = (num - 8) / 3 > 1 ? "千亿" : "亿";
294
+ text1 = (num - 8) / 4 > 1 ? "万亿" : text1;
295
+ text1 = (num - 8) / 7 > 1 ? "千万亿" : text1;
296
+ // tslint:disable-next-line:no-shadowed-variable
297
+ var fm = 1;
298
+ if ("亿" === text1) {
299
+ fm = 100000000;
300
+ } else if ("千亿" === text1) {
301
+ fm = 100000000000;
302
+ } else if ("万亿" === text1) {
303
+ fm = 1000000000000;
304
+ } else if ("千万亿" === text1) {
305
+ fm = 1000000000000000;
306
+ }
307
+ newValue[1] = text1;
308
+ newValue[0] = (value / fm).toFixed(index);
309
+ }
310
+ if (value < 1000) {
311
+ newValue[1] = "";
312
+ newValue[0] = "".concat(value);
313
+ }
314
+ return newValue.join("");
315
+ }
316
+ TransferUtil.numPlusUnit = numPlusUnit;
317
+ /**
318
+ * 字节转单位
319
+ * @param bytes - 字节
320
+ */
321
+ TransferUtil.getFileSizeByBytes = function (bytes) {
322
+ var sizes = ["B", "KB", "MB", "GB", "TB"];
323
+ if (bytes === 0) {
324
+ return "0B";
325
+ }
326
+ var i = Math.floor(Math.log(bytes) / Math.log(1024));
327
+ if (i === 0) {
328
+ return bytes + sizes[i];
329
+ }
330
+ return (bytes / Math.pow(1024, i)).toFixed(2) + sizes[i];
331
+ };
332
+ })(TransferUtil || (TransferUtil = {}));
333
+ exports.default = TransferUtil;
package/lib/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/lib/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -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,95 @@
1
+ "use strict";
2
+
3
+ var __importDefault = this && this.__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ /**
12
+ * url工具
13
+ * @description
14
+ * @author nanshen
15
+ * @creat 2021-09-15 14:40:22
16
+ */
17
+ var BaseUtil_1 = __importDefault(require("../base/BaseUtil"));
18
+ var ObjectUtil_1 = __importDefault(require("../object/ObjectUtil"));
19
+ var UrlUtil;
20
+ (function (UrlUtil) {
21
+ /**
22
+ * 把对象格式的参数转成键值对,并以&连接
23
+ * @param { Object } obj 对象
24
+ * @example
25
+ * objToUrlParam({a:213,b:2131}) => "a=213&b=2131"
26
+ */
27
+ function objToUrlParam(obj) {
28
+ if (BaseUtil_1.default.isEmpty(obj)) return '';
29
+ var result = '';
30
+ for (var key in obj) {
31
+ result += "".concat(key, "=").concat(encodeURIComponent(obj[key]), "&");
32
+ }
33
+ result = result.substr(0, result.length - 1);
34
+ return result;
35
+ }
36
+ UrlUtil.objToUrlParam = objToUrlParam;
37
+ /**
38
+ * 移除url的某一个参数
39
+ * @param { Array } paramNames 参数名称的数组
40
+ * @param { URL } url url地址
41
+ * @example
42
+ * deleteUrlParam(['a'],'http:XXX.cn?a=12&b=sad') => "http:XXX.cn?b=sad"
43
+ */
44
+ function deleteUrlParam(paramNames, url) {
45
+ var _a, _b;
46
+ if (url === void 0) {
47
+ url = location.href;
48
+ }
49
+ var newSearch = (_a = url === null || url === void 0 ? void 0 : url.split('?')) === null || _a === void 0 ? void 0 : _a[1];
50
+ if (!newSearch) return url;
51
+ var hostAndPath = (_b = url === null || url === void 0 ? void 0 : url.split('?')) === null || _b === void 0 ? void 0 : _b[0];
52
+ var urlSearch = new URLSearchParams(newSearch);
53
+ paramNames.forEach(function (param) {
54
+ var _a;
55
+ (_a = urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch['delete']) === null || _a === void 0 ? void 0 : _a.call(urlSearch, param);
56
+ });
57
+ return (urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch.toString()) ? "".concat(hostAndPath, "?").concat(urlSearch.toString()) : hostAndPath;
58
+ }
59
+ UrlUtil.deleteUrlParam = deleteUrlParam;
60
+ /**
61
+ * 解析url参数
62
+ * @param href url地址
63
+ * @example
64
+ * getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
65
+ */
66
+ UrlUtil.getUrlRequest = function (href) {
67
+ if (href === void 0) {
68
+ href = window.location.href;
69
+ }
70
+ var url = href === null || href === void 0 ? void 0 : href.slice(href === null || href === void 0 ? void 0 : href.indexOf('?'));
71
+ var theRequest = {};
72
+ if (url.indexOf('?') !== -1) {
73
+ var str = url.substr(1);
74
+ var strs = str.split('&');
75
+ for (var i = 0; i < strs.length; i++) {
76
+ theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]).replaceAll('#/', '');
77
+ }
78
+ }
79
+ return theRequest;
80
+ };
81
+ /**
82
+ * 不刷新改变url参数
83
+ * @param obj 对象
84
+ */
85
+ function setUrlParamsNotRefresh(obj) {
86
+ var urlParams = UrlUtil.getUrlRequest();
87
+ var str = objToUrlParam(ObjectUtil_1.default.mergeParams(obj, urlParams));
88
+ var url = "".concat(window.location.href.split('?')[0]).concat(str ? "?".concat(str) : '');
89
+ window.history.replaceState({
90
+ url: url
91
+ }, '', url);
92
+ }
93
+ UrlUtil.setUrlParamsNotRefresh = setUrlParamsNotRefresh;
94
+ })(UrlUtil || (UrlUtil = {}));
95
+ exports.default = UrlUtil;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "tools-min-ns",
3
+ "description": "工具包适用于前端以及node",
4
+ "version": "1.5.2",
5
+ "main": "lib/index.js",
6
+ "license": "MIT",
7
+ "author": "nanshen",
8
+ "module": "esm/index.js",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com"
12
+ },
13
+ "files": [
14
+ "esm",
15
+ "lib"
16
+ ],
17
+ "keywords": [
18
+ "tools"
19
+ ],
20
+ "scripts": {
21
+ "build": "NODE_ENV=production gulp",
22
+ "dev": "gulp -w",
23
+ "patch": "npm version patch",
24
+ "prepatch": "npm version prepatch",
25
+ "minor": "npm version minor",
26
+ "major": "npm version major",
27
+ "alpha": "npm version prerelease --preid=alpha",
28
+ "beta": "npm version prerelease --preid=beta"
29
+ },
30
+ "browserslist": [
31
+ "last 2 versions",
32
+ "Firefox ESR",
33
+ "> 1%",
34
+ "ie >= 11"
35
+ ],
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org/"
38
+ },
39
+ "devDependencies": {
40
+ "@babel/core": "^7.11.0",
41
+ "@babel/preset-env": "^7.11.0",
42
+ "@babel/preset-typescript": "^7.10.4",
43
+ "@types/node": "^20.5.0",
44
+ "@types/react": "^17.0.21",
45
+ "core-js": "3",
46
+ "del": "^5.1.0",
47
+ "gulp": "^4.0.2",
48
+ "gulp-babel": "^8.0.0",
49
+ "gulp-typescript": "^6.0.0-alpha.1",
50
+ "prettier": "^2.0.5",
51
+ "react": "^17.0.1",
52
+ "tslib": "^2.0.0",
53
+ "typescript": "^4.9.5"
54
+ },
55
+ "dependencies": {}
56
+ }