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,422 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * 树工具
5
+ * @description
6
+ * @author nanshen
7
+ * @creat 2021-09-15 10:31:35
8
+ */
9
+ var __read = this && this.__read || function (o, n) {
10
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
11
+ if (!m) return o;
12
+ var i = m.call(o),
13
+ r,
14
+ ar = [],
15
+ e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ } catch (error) {
19
+ e = {
20
+ error: error
21
+ };
22
+ } finally {
23
+ try {
24
+ if (r && !r.done && (m = i["return"])) m.call(i);
25
+ } finally {
26
+ if (e) throw e.error;
27
+ }
28
+ }
29
+ return ar;
30
+ };
31
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
32
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
33
+ if (ar || !(i in from)) {
34
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
35
+ ar[i] = from[i];
36
+ }
37
+ }
38
+ return to.concat(ar || Array.prototype.slice.call(from));
39
+ };
40
+ var __importDefault = this && this.__importDefault || function (mod) {
41
+ return mod && mod.__esModule ? mod : {
42
+ "default": mod
43
+ };
44
+ };
45
+ Object.defineProperty(exports, "__esModule", {
46
+ value: true
47
+ });
48
+ var BaseUtil_1 = __importDefault(require("../base/BaseUtil"));
49
+ var isEmpty = BaseUtil_1.default.isEmpty;
50
+ var TreeUtil;
51
+ (function (TreeUtil) {
52
+ /**
53
+ * @name 循环树改变原数组
54
+ * @param tree tree数组
55
+ * @param callback 回调(item:当前循环项,parent: 父对象)
56
+ * @param children children字段
57
+ * @param defaultParent 默认上级对象
58
+ *
59
+ */
60
+ function forEachTree(tree, callback, children, defaultParent) {
61
+ if (children === void 0) {
62
+ children = 'children';
63
+ }
64
+ tree === null || tree === void 0 ? void 0 : tree.forEach(function (item) {
65
+ callback(item, defaultParent);
66
+ forEachTree(item[children], callback, children, item);
67
+ });
68
+ return tree;
69
+ }
70
+ TreeUtil.forEachTree = forEachTree;
71
+ /**
72
+ * @name 查找树
73
+ * @param tree tree数组
74
+ * @param callback 回调(item:当前循环项,parent: 父对象)
75
+ * @param children children字段
76
+ * @param defaultParent 默认上级对象
77
+ */
78
+ function findTreeData(tree, callback, children, defaultParent) {
79
+ if (children === void 0) {
80
+ children = 'children';
81
+ }
82
+ for (var index = 0; index < ((tree === null || tree === void 0 ? void 0 : tree.length) || 0); index++) {
83
+ var item = tree[index];
84
+ var back = callback(item, defaultParent);
85
+ if (back) return item;
86
+ var isOk = findTreeData(item[children], callback, children, item);
87
+ if (isOk) return isOk;
88
+ }
89
+ return undefined;
90
+ }
91
+ TreeUtil.findTreeData = findTreeData;
92
+ /**
93
+ * @name 筛选树
94
+ * @param tree tree数组
95
+ * @param callback 回调(item:当前循环项,parent: 父对象)
96
+ * @param children children字段
97
+ * @param defaultParent 默认上级对象
98
+ */
99
+ function filterTreeData(tree, callback, children, defaultParent) {
100
+ if (children === void 0) {
101
+ children = 'children';
102
+ }
103
+ var list = [];
104
+ var fn = function fn(a, c, d) {
105
+ for (var index = 0; index < ((a === null || a === void 0 ? void 0 : a.length) || 0); index++) {
106
+ var item = a[index];
107
+ var back = c(item, d);
108
+ if (back) {
109
+ list.push(item);
110
+ }
111
+ fn(item[children], c, item);
112
+ }
113
+ };
114
+ fn(tree, callback, defaultParent);
115
+ return list;
116
+ }
117
+ TreeUtil.filterTreeData = filterTreeData;
118
+ /**
119
+ * @name 列表转树
120
+ * @param list 数组
121
+ * @param fieldNames 映射对象
122
+ */
123
+ function getTreeByList(list, fieldNames) {
124
+ var _a = fieldNames || {},
125
+ _b = _a.label,
126
+ label = _b === void 0 ? 'name' : _b,
127
+ _c = _a.value,
128
+ value = _c === void 0 ? 'id' : _c,
129
+ _d = _a.parent,
130
+ parent = _d === void 0 ? 'pid' : _d,
131
+ _e = _a.children,
132
+ children = _e === void 0 ? 'children' : _e,
133
+ rootPid = _a.rootPid;
134
+ if (!(list === null || list === void 0 ? void 0 : list.length)) return [];
135
+ var inList = JSON.parse(JSON.stringify(list));
136
+ var menuObj = {};
137
+ inList.forEach(function (item) {
138
+ item.key = String(item[value]);
139
+ item.title = item[label];
140
+ item[children] = [];
141
+ item.parent = [];
142
+ menuObj[item[value]] = item;
143
+ });
144
+ inList.forEach(function (item) {
145
+ var _a, _b;
146
+ var childList = (_a = menuObj === null || menuObj === void 0 ? void 0 : menuObj[item === null || item === void 0 ? void 0 : item[parent]]) === null || _a === void 0 ? void 0 : _a[children];
147
+ if (childList) childList.push(item);
148
+ var parentData = menuObj === null || menuObj === void 0 ? void 0 : menuObj[item === null || item === void 0 ? void 0 : item[parent]];
149
+ if (parentData) (_b = item === null || item === void 0 ? void 0 : item.parent) === null || _b === void 0 ? void 0 : _b.push(parentData);
150
+ });
151
+ var rootIds = inList.filter(function (item) {
152
+ var _a;
153
+ return ((_a = item === null || item === void 0 ? void 0 : item.parent) === null || _a === void 0 ? void 0 : _a.length) === 0;
154
+ }).map(function (e) {
155
+ return e[value];
156
+ });
157
+ var l = forEachTree(inList.filter(function (item) {
158
+ var id = item[value];
159
+ if (rootPid === undefined) {
160
+ return rootIds.includes(id);
161
+ }
162
+ return String(id) === String(rootPid);
163
+ }), function (e) {
164
+ var _a;
165
+ delete e.parent;
166
+ if (!((_a = e[children]) === null || _a === void 0 ? void 0 : _a.length)) delete e[children];
167
+ }, children);
168
+ return l;
169
+ }
170
+ TreeUtil.getTreeByList = getTreeByList;
171
+ /**
172
+ * @name 树转列表
173
+ * @param tree 数组
174
+ */
175
+ function getListByTree(tree, children) {
176
+ var _a;
177
+ if (children === void 0) {
178
+ children = 'children';
179
+ }
180
+ var newList = (_a = {}, _a[children] = tree, _a);
181
+ return treeData2List(newList, children);
182
+ }
183
+ TreeUtil.getListByTree = getListByTree;
184
+ /**
185
+ * @name 获取树中id路径数组
186
+ * @param tree 树
187
+ * @param id 主键
188
+ * @param fieldNames 映射对象
189
+ */
190
+ function getIdPathByTree(tree, id, fieldNames) {
191
+ var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
192
+ _b = _a.value,
193
+ value = _b === void 0 ? 'id' : _b,
194
+ _c = _a.parent,
195
+ parent = _c === void 0 ? 'pid' : _c,
196
+ _d = _a.children,
197
+ children = _d === void 0 ? 'children' : _d,
198
+ _e = _a.rootPid,
199
+ rootPid = _e === void 0 ? undefined : _e;
200
+ if (BaseUtil_1.default.isEmpty(id)) return [];
201
+ var idList = [id];
202
+ var list = getListByTree(tree);
203
+ var getList = function getList(importOid) {
204
+ forEachTree(tree, function (info) {
205
+ if (String(info[value]) === String(importOid)) {
206
+ if (parent in info && info[parent] && list.some(function (e) {
207
+ return String(e[value]) === String(info[parent]);
208
+ })) {
209
+ idList.unshift(info === null || info === void 0 ? void 0 : info[parent]);
210
+ getList(info === null || info === void 0 ? void 0 : info[parent]);
211
+ }
212
+ }
213
+ }, children);
214
+ };
215
+ getList(id);
216
+ if (!BaseUtil_1.default.isEmpty(rootPid)) {
217
+ var idx = idList.findIndex(function (item) {
218
+ return String(item) === String(rootPid);
219
+ });
220
+ return idx === -1 ? idList : idList.slice(idx);
221
+ }
222
+ return idList;
223
+ }
224
+ TreeUtil.getIdPathByTree = getIdPathByTree;
225
+ /**
226
+ * @name 字符串分割转为树结构
227
+ * @param str string
228
+ * @param splitStr /
229
+ * @param fieldNames 映射对象
230
+ * @example
231
+ *
232
+ * `一级选项 1/二级选项 1/三级选项 1
233
+ 一级选项 1/二级选项 1/三级选项 2
234
+ 一级选项 2/二级选项 1`
235
+ //转换后
236
+ [
237
+ {
238
+ name: '一级选项 1',
239
+ id: '一级选项 1',
240
+ children: [
241
+ {
242
+ name: '二级选项 1',
243
+ id: '二级选项 1',
244
+ pid: '一级选项 1',
245
+ children: [
246
+ {
247
+ name: '三级选项 1',
248
+ id: '三级选项 1',
249
+ pid: '二级选项 1',
250
+ },
251
+ {
252
+ name: '三级选项 2',
253
+ id: '三级选项 2',
254
+ pid: '二级选项 1',
255
+ },
256
+ ],
257
+ },
258
+ ],
259
+ },
260
+ {
261
+ name: '一级选项 2',
262
+ id: '一级选项 2',
263
+ children: [
264
+ {
265
+ name: '二级选项 1',
266
+ id: '二级选项 1',
267
+ pid: '一级选项 2',
268
+ },
269
+ ],
270
+ },
271
+ ]
272
+ */
273
+ function strSplit2tree(str, splitStr, fieldNames) {
274
+ if (splitStr === void 0) {
275
+ splitStr = '/';
276
+ }
277
+ var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
278
+ _b = _a.label,
279
+ label = _b === void 0 ? 'name' : _b,
280
+ _c = _a.value,
281
+ value = _c === void 0 ? 'id' : _c,
282
+ _d = _a.parent,
283
+ parent = _d === void 0 ? 'pid' : _d,
284
+ _e = _a.children,
285
+ children = _e === void 0 ? 'children' : _e;
286
+ var menuObj = {};
287
+ var arr = [];
288
+ __spreadArray([], __read(new Set(str.split('\n'))), false).forEach(function (text) {
289
+ var itemArr = text.split(splitStr).map(function (e) {
290
+ return e.trim();
291
+ }).filter(function (e) {
292
+ return e;
293
+ });
294
+ arr.push.apply(arr, __spreadArray([], __read(itemArr.map(function (e, i) {
295
+ var _a;
296
+ return _a = {}, _a[label] = e, _a[value] = e, _a[parent] = itemArr[i - 1], _a._id = String(itemArr.slice(0, i + 1)), _a._pid = String(itemArr.slice(0, i)), _a;
297
+ })), false));
298
+ });
299
+ arr = __spreadArray([], __read(new Set(arr.map(function (e) {
300
+ return JSON.stringify(e);
301
+ }))), false).map(function (e) {
302
+ return JSON.parse(e);
303
+ });
304
+ arr.forEach(function (item) {
305
+ item[children] = [];
306
+ menuObj[item._id] = item;
307
+ });
308
+ arr = arr.filter(function (item) {
309
+ var _a;
310
+ var childList = (_a = menuObj[item === null || item === void 0 ? void 0 : item._pid]) === null || _a === void 0 ? void 0 : _a[children];
311
+ if (childList) childList.push(item);
312
+ return !(parent in item);
313
+ });
314
+ return forEachTree(arr, function (e) {
315
+ var _a;
316
+ delete e._id;
317
+ delete e._pid;
318
+ if (!((_a = e === null || e === void 0 ? void 0 : e[children]) === null || _a === void 0 ? void 0 : _a.length)) delete e[children];
319
+ }, children);
320
+ }
321
+ TreeUtil.strSplit2tree = strSplit2tree;
322
+ /**
323
+ * @name 树结构转为字符串分割
324
+ * @param tree 树
325
+ * @param splitStr /
326
+ * @param fieldNames 映射对象
327
+ * @example
328
+ *
329
+ * [
330
+ {
331
+ name: '一级选项 1',
332
+ id: '一级选项 1',
333
+ children: [
334
+ {
335
+ name: '二级选项 1',
336
+ id: '二级选项 1',
337
+ pid: '一级选项 1',
338
+ children: [
339
+ {
340
+ name: '三级选项 1',
341
+ id: '三级选项 1',
342
+ pid: '二级选项 1',
343
+ },
344
+ {
345
+ name: '三级选项 2',
346
+ id: '三级选项 2',
347
+ pid: '二级选项 1',
348
+ },
349
+ ],
350
+ },
351
+ ],
352
+ },
353
+ {
354
+ name: '一级选项 2',
355
+ id: '一级选项 2',
356
+ children: [
357
+ {
358
+ name: '二级选项 1',
359
+ id: '二级选项 1',
360
+ pid: '一级选项 2',
361
+ },
362
+ ],
363
+ },
364
+ ]
365
+ //转换后
366
+ `一级选项 1/二级选项 1/三级选项 1
367
+ 一级选项 1/二级选项 1/三级选项 2
368
+ 一级选项 2/二级选项 1`
369
+ */
370
+ function tree2strSplit(tree, splitStr, fieldNames) {
371
+ if (splitStr === void 0) {
372
+ splitStr = '/';
373
+ }
374
+ var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
375
+ _b = _a.label,
376
+ label = _b === void 0 ? 'name' : _b,
377
+ _c = _a.parent,
378
+ parent = _c === void 0 ? 'pid' : _c,
379
+ _d = _a.children,
380
+ children = _d === void 0 ? 'children' : _d;
381
+ var strArr = [];
382
+ var treeArr = JSON.parse(JSON.stringify(tree));
383
+ forEachTree(treeArr, function (item, parentData) {
384
+ var _a, _b, _c;
385
+ item[parent] = "".concat((_a = parentData === null || parentData === void 0 ? void 0 : parentData[parent]) !== null && _a !== void 0 ? _a : '', "/").concat((_b = parentData === null || parentData === void 0 ? void 0 : parentData[label]) !== null && _b !== void 0 ? _b : '');
386
+ if (parentData && !((_c = item === null || item === void 0 ? void 0 : item[children]) === null || _c === void 0 ? void 0 : _c.length)) {
387
+ strArr.push("".concat(item[parent], "/").concat(item[label]).split(splitStr).filter(function (e) {
388
+ return e;
389
+ }).join(splitStr));
390
+ }
391
+ }, children);
392
+ return strArr.join('\n');
393
+ }
394
+ TreeUtil.tree2strSplit = tree2strSplit;
395
+ })(TreeUtil || (TreeUtil = {}));
396
+ exports.default = TreeUtil;
397
+ /**
398
+ * @name 这个是需要children包着的树对象
399
+ * @param element 树对象
400
+ * @param children 自定义children
401
+ */
402
+ function treeData2List(element, children) {
403
+ if (children === void 0) {
404
+ children = 'children';
405
+ }
406
+ var array = [];
407
+ var getList = function getList(item) {
408
+ var _a;
409
+ var newItem = JSON.parse(JSON.stringify(item || '{}')); //序列化
410
+ delete newItem[children];
411
+ if ((_a = item[children]) === null || _a === void 0 ? void 0 : _a.length) {
412
+ if (!isEmpty(newItem)) array.push(newItem);
413
+ item[children].forEach(function (el) {
414
+ return getList(el);
415
+ });
416
+ } else if (!isEmpty(newItem)) {
417
+ array.push(newItem);
418
+ }
419
+ };
420
+ getList(element);
421
+ return array;
422
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * 数据校验
3
+ * @description 基础数据校验
4
+ * @author nanshen
5
+ * @creat 2021-09-15 10:30:05
6
+ */
7
+ declare namespace BaseUtil {
8
+ /**
9
+ * 判断是否为 undefined
10
+ * @param obj 任意对象
11
+ * @returns 是/否
12
+ */
13
+ const isUndefined: (obj: any) => obj is undefined;
14
+ /**
15
+ * 判断是否为 null
16
+ * @param obj 任意对象
17
+ * @returns 是/否
18
+ */
19
+ const isNull: (obj: any) => obj is null;
20
+ /**
21
+ * 判断是否为 Array 类型
22
+ * @param obj 任意对象
23
+ * @returns 是/否
24
+ */
25
+ const isArray: (obj: any) => obj is any[];
26
+ /**
27
+ * 判断是否为 Function 类型
28
+ * @param obj 任意对象
29
+ * @returns 是/否
30
+ */
31
+ const isFunction: (obj: any) => obj is Function;
32
+ /**
33
+ * 判断是否为 Boolean 类型
34
+ * @param obj 任意对象
35
+ * @returns 是/否
36
+ */
37
+ const isBoolean: (obj: any) => obj is boolean;
38
+ /**
39
+ * 判断是否为 String 类型
40
+ * @param obj 任意对象
41
+ * @returns 是/否
42
+ */
43
+ const isString: (obj: any) => obj is string;
44
+ /**
45
+ * 判断是否为 Number 类型
46
+ * @param obj 任意对象
47
+ * @returns 是/否
48
+ */
49
+ const isNumber: (obj: any) => obj is number;
50
+ /**
51
+ * 判断是否为 RegExp 类型
52
+ * @param obj 任意对象
53
+ * @returns 是/否
54
+ */
55
+ const isRegExp: (obj: any) => obj is RegExp;
56
+ /**
57
+ * 判断是否为 Object 类型
58
+ * @param obj 任意对象
59
+ * @returns 是/否
60
+ */
61
+ const isObject: (obj: any) => obj is object;
62
+ /**
63
+ * 判断是否为 Date 类型
64
+ * @param obj 任意对象
65
+ * @returns 是/否
66
+ */
67
+ const isDate: (obj: any) => obj is Date;
68
+ /**
69
+ * 判断是否为 Error 类型
70
+ * @param obj 任意对象
71
+ * @returns 是/否
72
+ */
73
+ const isError: (obj: any) => obj is Error;
74
+ /**
75
+ * 获取对象的类型
76
+ * @param obj 任意对象
77
+ * @returns undefined | null | array | function | boolean | string | number | regexp | object | date | error
78
+ * @example
79
+ * getType(null) => 'null'
80
+ */
81
+ const getType: (obj: any) => string;
82
+ /**
83
+ * 判断是否为空,包括空对象,空数组,空字符串,null,undefined等
84
+ * @param obj 任意对象
85
+ * @example
86
+ * isEmpty(12) => false
87
+ * isEmpty(null) => true
88
+ */
89
+ const isEmpty: (obj: any) => obj is "" | null | undefined;
90
+ }
91
+ export default BaseUtil;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ /**
7
+ * 数据校验
8
+ * @description 基础数据校验
9
+ * @author nanshen
10
+ * @creat 2021-09-15 10:30:05
11
+ */
12
+ var BaseUtil;
13
+ (function (BaseUtil) {
14
+ /**
15
+ * 创建一个自定义的 typeof 函数
16
+ * @param {String} type 类型
17
+ * @returns {Function} 返回一个可判断特定类型的谓词函数
18
+ */
19
+ var _createTypeOf = function _createTypeOf(type) {
20
+ return function (obj) {
21
+ return Object.prototype.toString.call(obj) === "[object ".concat(type, "]");
22
+ };
23
+ };
24
+ /**
25
+ * 判断是否为 undefined
26
+ * @param obj 任意对象
27
+ * @returns 是/否
28
+ */
29
+ BaseUtil.isUndefined = _createTypeOf("Undefined");
30
+ /**
31
+ * 判断是否为 null
32
+ * @param obj 任意对象
33
+ * @returns 是/否
34
+ */
35
+ BaseUtil.isNull = _createTypeOf("Null");
36
+ /**
37
+ * 判断是否为 Array 类型
38
+ * @param obj 任意对象
39
+ * @returns 是/否
40
+ */
41
+ BaseUtil.isArray = Array.isArray || _createTypeOf("Array");
42
+ /**
43
+ * 判断是否为 Function 类型
44
+ * @param obj 任意对象
45
+ * @returns 是/否
46
+ */
47
+ BaseUtil.isFunction = _createTypeOf("Function");
48
+ /**
49
+ * 判断是否为 Boolean 类型
50
+ * @param obj 任意对象
51
+ * @returns 是/否
52
+ */
53
+ BaseUtil.isBoolean = _createTypeOf("Boolean");
54
+ /**
55
+ * 判断是否为 String 类型
56
+ * @param obj 任意对象
57
+ * @returns 是/否
58
+ */
59
+ BaseUtil.isString = _createTypeOf("String");
60
+ /**
61
+ * 判断是否为 Number 类型
62
+ * @param obj 任意对象
63
+ * @returns 是/否
64
+ */
65
+ BaseUtil.isNumber = _createTypeOf("Number");
66
+ /**
67
+ * 判断是否为 RegExp 类型
68
+ * @param obj 任意对象
69
+ * @returns 是/否
70
+ */
71
+ BaseUtil.isRegExp = _createTypeOf("RegExp");
72
+ /**
73
+ * 判断是否为 Object 类型
74
+ * @param obj 任意对象
75
+ * @returns 是/否
76
+ */
77
+ BaseUtil.isObject = _createTypeOf("Object");
78
+ /**
79
+ * 判断是否为 Date 类型
80
+ * @param obj 任意对象
81
+ * @returns 是/否
82
+ */
83
+ BaseUtil.isDate = _createTypeOf("Date");
84
+ /**
85
+ * 判断是否为 Error 类型
86
+ * @param obj 任意对象
87
+ * @returns 是/否
88
+ */
89
+ BaseUtil.isError = _createTypeOf("Error");
90
+ /**
91
+ * 获取对象的类型
92
+ * @param obj 任意对象
93
+ * @returns undefined | null | array | function | boolean | string | number | regexp | object | date | error
94
+ * @example
95
+ * getType(null) => 'null'
96
+ */
97
+ BaseUtil.getType = function (obj) {
98
+ if (BaseUtil.isUndefined(obj)) {
99
+ return "undefined";
100
+ }
101
+ if (BaseUtil.isNull(obj)) {
102
+ return "null";
103
+ }
104
+ if (BaseUtil.isArray(obj)) {
105
+ return "array";
106
+ }
107
+ if (BaseUtil.isFunction(obj)) {
108
+ return "function";
109
+ }
110
+ if (BaseUtil.isBoolean(obj)) {
111
+ return "boolean";
112
+ }
113
+ if (BaseUtil.isString(obj)) {
114
+ return "string";
115
+ }
116
+ if (BaseUtil.isNumber(obj)) {
117
+ return "number";
118
+ }
119
+ if (BaseUtil.isRegExp(obj)) {
120
+ return "regexp";
121
+ }
122
+ if (BaseUtil.isObject(obj)) {
123
+ return "object";
124
+ }
125
+ if (BaseUtil.isDate(obj)) {
126
+ return "date";
127
+ }
128
+ if (BaseUtil.isError(obj)) {
129
+ return "error";
130
+ }
131
+ return typeof obj;
132
+ };
133
+ /**
134
+ * 判断是否为空,包括空对象,空数组,空字符串,null,undefined等
135
+ * @param obj 任意对象
136
+ * @example
137
+ * isEmpty(12) => false
138
+ * isEmpty(null) => true
139
+ */
140
+ BaseUtil.isEmpty = function (obj) {
141
+ if (BaseUtil.isString(obj)) {
142
+ obj = obj.trim();
143
+ }
144
+ for (var _ in obj) {
145
+ return false;
146
+ }
147
+ if (BaseUtil.isBoolean(obj) || BaseUtil.isNumber(obj) || BaseUtil.isFunction(obj) || BaseUtil.isDate(obj) || BaseUtil.isError(obj) || BaseUtil.isRegExp(obj)) {
148
+ return false;
149
+ }
150
+ return true;
151
+ };
152
+ })(BaseUtil || (BaseUtil = {}));
153
+ exports.default = BaseUtil;