tools-min-ns 1.8.2 → 1.9.0

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 (166) hide show
  1. package/README.md +1 -1
  2. package/esm/array/ArrayUtil.d.ts +109 -0
  3. package/esm/array/ArrayUtil.js +242 -0
  4. package/esm/array/TreeUtil.d.ts +158 -0
  5. package/esm/array/TreeUtil.js +428 -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 +58 -0
  9. package/esm/browser/BrowserUtil.js +370 -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 +111 -0
  13. package/esm/check/CheckUtil.js +516 -0
  14. package/esm/common.d.ts +51 -0
  15. package/esm/common.js +52 -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 +268 -0
  23. package/esm/date/DateUtil.js +789 -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/file/FileUtil.d.ts +10 -0
  29. package/esm/file/FileUtil.js +182 -0
  30. package/esm/func/FunctionUtil.d.ts +77 -0
  31. package/esm/func/FunctionUtil.js +215 -0
  32. package/esm/index.d.ts +19 -0
  33. package/esm/index.js +19 -0
  34. package/esm/number/NumberUtil.d.ts +96 -0
  35. package/esm/number/NumberUtil.js +256 -0
  36. package/esm/object/ObjectUtil.d.ts +46 -0
  37. package/esm/object/ObjectUtil.js +166 -0
  38. package/esm/pwd/PasswordUtil.d.ts +33 -0
  39. package/esm/pwd/PasswordUtil.js +68 -0
  40. package/esm/pwd/crypto.d.ts +6 -0
  41. package/esm/pwd/crypto.js +1824 -0
  42. package/esm/request/RequestUtil.d.ts +66 -0
  43. package/esm/request/RequestUtil.js +237 -0
  44. package/esm/request/jsonp.d.ts +18 -0
  45. package/esm/request/jsonp.js +73 -0
  46. package/esm/request/mgop/env.d.ts +7 -0
  47. package/esm/request/mgop/env.js +15 -0
  48. package/esm/request/mgop/index.d.ts +3 -0
  49. package/esm/request/mgop/index.js +276 -0
  50. package/esm/request/mgop/responseCode.d.ts +20 -0
  51. package/esm/request/mgop/responseCode.js +37 -0
  52. package/esm/request/mgop/type.d.ts +34 -0
  53. package/esm/request/mgop/type.js +1 -0
  54. package/esm/request/uniRquest/index.d.ts +2 -0
  55. package/esm/request/uniRquest/index.js +66 -0
  56. package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
  57. package/esm/request/uniRquest/miniapp/index.js +29 -0
  58. package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  59. package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
  60. package/esm/request/uniRquest/types.d.ts +65 -0
  61. package/esm/request/uniRquest/types.js +36 -0
  62. package/esm/request/uniRquest/utils.d.ts +9 -0
  63. package/esm/request/uniRquest/utils.js +69 -0
  64. package/esm/request/uniRquest/web/index.d.ts +2 -0
  65. package/esm/request/uniRquest/web/index.js +85 -0
  66. package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  67. package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
  68. package/esm/request/uniRquest/weex/index.d.ts +14 -0
  69. package/esm/request/uniRquest/weex/index.js +59 -0
  70. package/esm/storage/StorageUtil.d.ts +19 -0
  71. package/esm/storage/StorageUtil.js +75 -0
  72. package/esm/string/StringUtil.d.ts +398 -0
  73. package/esm/string/StringUtil.js +570 -0
  74. package/esm/system/SystemUtil.d.ts +46 -0
  75. package/esm/system/SystemUtil.js +122 -0
  76. package/esm/transfer/MapTransferUtil.d.ts +54 -0
  77. package/esm/transfer/MapTransferUtil.js +160 -0
  78. package/esm/transfer/TransferUtil.d.ts +98 -0
  79. package/esm/transfer/TransferUtil.js +323 -0
  80. package/esm/types.d.ts +25 -0
  81. package/esm/types.js +1 -0
  82. package/esm/url/UrlUtil.d.ts +30 -0
  83. package/esm/url/UrlUtil.js +85 -0
  84. package/lib/array/ArrayUtil.d.ts +109 -0
  85. package/lib/array/ArrayUtil.js +252 -0
  86. package/lib/array/TreeUtil.d.ts +158 -0
  87. package/lib/array/TreeUtil.js +438 -0
  88. package/lib/base/BaseUtil.d.ts +91 -0
  89. package/lib/base/BaseUtil.js +153 -0
  90. package/lib/browser/BrowserUtil.d.ts +58 -0
  91. package/lib/browser/BrowserUtil.js +380 -0
  92. package/lib/browser/fingerprint.d.ts +120 -0
  93. package/lib/browser/fingerprint.js +1500 -0
  94. package/lib/check/CheckUtil.d.ts +111 -0
  95. package/lib/check/CheckUtil.js +526 -0
  96. package/lib/common.d.ts +51 -0
  97. package/lib/common.js +58 -0
  98. package/lib/config.d.ts +7 -0
  99. package/lib/config.js +12 -0
  100. package/lib/cookie/CookieUtil.d.ts +56 -0
  101. package/lib/cookie/CookieUtil.js +22 -0
  102. package/lib/cookie/cookie.d.ts +2 -0
  103. package/lib/cookie/cookie.js +109 -0
  104. package/lib/date/DateUtil.d.ts +268 -0
  105. package/lib/date/DateUtil.js +799 -0
  106. package/lib/env/EnvUtil.d.ts +27 -0
  107. package/lib/env/EnvUtil.js +39 -0
  108. package/lib/env/env.d.ts +41 -0
  109. package/lib/env/env.js +112 -0
  110. package/lib/file/FileUtil.d.ts +10 -0
  111. package/lib/file/FileUtil.js +192 -0
  112. package/lib/func/FunctionUtil.d.ts +77 -0
  113. package/lib/func/FunctionUtil.js +225 -0
  114. package/lib/index.d.ts +19 -0
  115. package/lib/index.js +144 -0
  116. package/lib/number/NumberUtil.d.ts +96 -0
  117. package/lib/number/NumberUtil.js +266 -0
  118. package/lib/object/ObjectUtil.d.ts +46 -0
  119. package/lib/object/ObjectUtil.js +176 -0
  120. package/lib/pwd/PasswordUtil.d.ts +33 -0
  121. package/lib/pwd/PasswordUtil.js +78 -0
  122. package/lib/pwd/crypto.d.ts +6 -0
  123. package/lib/pwd/crypto.js +1829 -0
  124. package/lib/request/RequestUtil.d.ts +66 -0
  125. package/lib/request/RequestUtil.js +278 -0
  126. package/lib/request/jsonp.d.ts +18 -0
  127. package/lib/request/jsonp.js +80 -0
  128. package/lib/request/mgop/env.d.ts +7 -0
  129. package/lib/request/mgop/env.js +21 -0
  130. package/lib/request/mgop/index.d.ts +3 -0
  131. package/lib/request/mgop/index.js +289 -0
  132. package/lib/request/mgop/responseCode.d.ts +20 -0
  133. package/lib/request/mgop/responseCode.js +42 -0
  134. package/lib/request/mgop/type.d.ts +34 -0
  135. package/lib/request/mgop/type.js +5 -0
  136. package/lib/request/uniRquest/index.d.ts +2 -0
  137. package/lib/request/uniRquest/index.js +77 -0
  138. package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
  139. package/lib/request/uniRquest/miniapp/index.js +35 -0
  140. package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  141. package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
  142. package/lib/request/uniRquest/types.d.ts +65 -0
  143. package/lib/request/uniRquest/types.js +42 -0
  144. package/lib/request/uniRquest/utils.d.ts +9 -0
  145. package/lib/request/uniRquest/utils.js +83 -0
  146. package/lib/request/uniRquest/web/index.d.ts +2 -0
  147. package/lib/request/uniRquest/web/index.js +91 -0
  148. package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  149. package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
  150. package/lib/request/uniRquest/weex/index.d.ts +14 -0
  151. package/lib/request/uniRquest/weex/index.js +65 -0
  152. package/lib/storage/StorageUtil.d.ts +19 -0
  153. package/lib/storage/StorageUtil.js +85 -0
  154. package/lib/string/StringUtil.d.ts +398 -0
  155. package/lib/string/StringUtil.js +580 -0
  156. package/lib/system/SystemUtil.d.ts +46 -0
  157. package/lib/system/SystemUtil.js +132 -0
  158. package/lib/transfer/MapTransferUtil.d.ts +54 -0
  159. package/lib/transfer/MapTransferUtil.js +165 -0
  160. package/lib/transfer/TransferUtil.d.ts +98 -0
  161. package/lib/transfer/TransferUtil.js +333 -0
  162. package/lib/types.d.ts +25 -0
  163. package/lib/types.js +5 -0
  164. package/lib/url/UrlUtil.d.ts +30 -0
  165. package/lib/url/UrlUtil.js +95 -0
  166. package/package.json +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ cnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
- ## v1.8.2
8
+ ## v1.9.0
9
9
 
10
10
  > CheckUtil getFormItemRules 新增required参数
11
11
 
@@ -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;
@@ -0,0 +1,242 @@
1
+ /**
2
+ * 数组工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 10:31:35
6
+ */
7
+ var __read = this && this.__read || function (o, n) {
8
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
9
+ if (!m) return o;
10
+ var i = m.call(o),
11
+ r,
12
+ ar = [],
13
+ e;
14
+ try {
15
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
16
+ } catch (error) {
17
+ e = {
18
+ error: error
19
+ };
20
+ } finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ } finally {
24
+ if (e) throw e.error;
25
+ }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
38
+ import NumberUtil from '../number/NumberUtil';
39
+ var ArrayUtil;
40
+ (function (ArrayUtil) {
41
+ /**
42
+ * 对象数组去重
43
+ * @param array 去重对象
44
+ * @param key 去重key
45
+ * @param isSaveLast 默认true ,true返回重复最后一个对象,false返回重复第一个对象
46
+ * @example
47
+ * const array = [{a:1,b:3},{a:1,b:2},{a:2,b:1}]
48
+ * arrayWeightRemoval(array,'a',true) => [{a:1,b:2},{a:2,b:1}]
49
+ * arrayWeightRemoval(array,'a',false) => [{a:1,b:3},{a:2,b:1}]
50
+ */
51
+ ArrayUtil.arrayWeightRemoval = function (array, key, isSaveLast) {
52
+ var _a;
53
+ if (array === void 0) {
54
+ array = [];
55
+ }
56
+ if (isSaveLast === void 0) {
57
+ isSaveLast = true;
58
+ }
59
+ if (!array.length || key === undefined || ((_a = array === null || array === void 0 ? void 0 : array[0]) === null || _a === void 0 ? void 0 : _a[key]) === undefined) {
60
+ return [];
61
+ }
62
+ var arrayMap = new Map();
63
+ var region = [];
64
+ array.forEach(function (element) {
65
+ if (isSaveLast) {
66
+ arrayMap.set(element[key], element);
67
+ } else {
68
+ if (!arrayMap.has(element[key])) arrayMap.set(element[key], element);
69
+ }
70
+ });
71
+ arrayMap.forEach(function (ele) {
72
+ if (ele) {
73
+ region.push(ele);
74
+ }
75
+ });
76
+ return region;
77
+ };
78
+ /**
79
+ * 数组去重
80
+ * @param { (number | string)[]} arr 数组
81
+ * @example
82
+ * unique([1,3,1]) =>[1,3]
83
+ */
84
+ ArrayUtil.unique = function (arr) {
85
+ if (!(arr === null || arr === void 0 ? void 0 : arr.length)) return [];
86
+ var list = __spreadArray([], __read(new Set(arr)), false);
87
+ return list;
88
+ };
89
+ /**
90
+ * 求两个集合的并集
91
+ * @param { (number | string)[]} a 集合a
92
+ * @param { (number | string)[]} b 集合b
93
+ * @example
94
+ * union([1,3,4],[1,2]) => [1,2,3,4]
95
+ */
96
+ ArrayUtil.union = function (a, b) {
97
+ if (!(a === null || a === void 0 ? void 0 : a.length)) return [];
98
+ if (!(b === null || b === void 0 ? void 0 : b.length)) return [];
99
+ var aArr = new Set(a);
100
+ var bArr = new Set(b);
101
+ var list = __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(aArr), false), __read(bArr), false))), false);
102
+ return list;
103
+ };
104
+ /**
105
+ * 求两个集合的交集
106
+ * @param { (number | string)[]} a 集合a
107
+ * @param { (number | string)[]} b 集合b
108
+ * @example
109
+ * intersect([1,3,4],[1,2]) => [1]
110
+ */
111
+ ArrayUtil.intersect = function (a, b) {
112
+ if (!(a === null || a === void 0 ? void 0 : a.length)) return [];
113
+ if (!(b === null || b === void 0 ? void 0 : b.length)) return [];
114
+ var aArr = new Set(a);
115
+ var bArr = new Set(b);
116
+ var list = __spreadArray([], __read(new Set(__spreadArray([], __read(aArr), false).filter(function (x) {
117
+ return bArr.has(x);
118
+ }))), false);
119
+ return list;
120
+ };
121
+ /**
122
+ * 求两个集合的差集
123
+ * @param { (number | string)[]} a 集合a
124
+ * @param { (number | string)[]} b 集合b
125
+ * @example
126
+ * difference([1,2,3],[1]) => [2,3]
127
+ */
128
+ ArrayUtil.difference = function (a, b) {
129
+ var aArr = new Set(a);
130
+ var bArr = new Set(b);
131
+ var list = __spreadArray([], __read(new Set(__spreadArray([], __read(aArr), false).filter(function (x) {
132
+ return !bArr.has(x);
133
+ }))), false);
134
+ return list;
135
+ };
136
+ /**
137
+ * 最大值
138
+ * @param {number[]} arr 数组
139
+ * @example
140
+ * max([1,2,3]) => 3
141
+ */
142
+ ArrayUtil.max = function (arr) {
143
+ if (!(arr === null || arr === void 0 ? void 0 : arr.length)) return 0;
144
+ return Math.max.apply(null, arr);
145
+ };
146
+ /**
147
+ * 最小值
148
+ * @export
149
+ * @param {number[]} arr 数组
150
+ * @example
151
+ * min([1,2,3]) => 1
152
+ */
153
+ ArrayUtil.min = function (arr) {
154
+ if (!(arr === null || arr === void 0 ? void 0 : arr.length)) return 0;
155
+ return Math.min.apply(null, arr);
156
+ };
157
+ /**
158
+ * 求和
159
+ * @export
160
+ * @param {number[]} arr 数字数组
161
+ * @example
162
+ * sum([1,2]) => 3
163
+ */
164
+ ArrayUtil.sum = function (arr) {
165
+ return arr.reduce(function (a, b) {
166
+ return NumberUtil.floatAdd(a, b);
167
+ }, 0);
168
+ };
169
+ /**
170
+ * 平均值
171
+ * @export
172
+ * @param {number[]} arr 数字数组
173
+ * @example
174
+ * average([1,2,3]) => 2
175
+ */
176
+ ArrayUtil.average = function (arr) {
177
+ if (!(arr === null || arr === void 0 ? void 0 : arr.length)) return 0;
178
+ return ArrayUtil.sum(arr) / arr.length;
179
+ };
180
+ /**
181
+ * 删除其中一个元素
182
+ * @export
183
+ * @param {(number | string)[]} arr 数组
184
+ * @param {(number | string)} ele 要删除的元素
185
+ * @example
186
+ * remove([1,2,3],3) => [1,2]
187
+ */
188
+ ArrayUtil.remove = function (arr, ele) {
189
+ if (!(arr === null || arr === void 0 ? void 0 : arr.length)) return [];
190
+ var index = arr.indexOf(ele);
191
+ if (index > -1) {
192
+ arr.splice(index, 1);
193
+ }
194
+ return arr;
195
+ };
196
+ /**
197
+ * 数组排序
198
+ * @param {number[]} arr 数组
199
+ * @param {number} type 1:从小到大 2:从大到小 3:随机
200
+ * @example
201
+ * sort([1,2,3],1) => [1,2,3]
202
+ * sort([1,2,3],2) => [3,2,1]
203
+ * sort([1,2,3],3) => [1,3,2]
204
+ */
205
+ ArrayUtil.sort = function (arr, type) {
206
+ if (type === void 0) {
207
+ type = 1;
208
+ }
209
+ if (!(arr === null || arr === void 0 ? void 0 : arr.length)) return [];
210
+ return arr.sort(function (a, b) {
211
+ switch (type) {
212
+ case 1:
213
+ return a - b;
214
+ case 2:
215
+ return b - a;
216
+ case 3:
217
+ return Math.random() - 0.5;
218
+ default:
219
+ return a - b;
220
+ }
221
+ });
222
+ };
223
+ /**
224
+ * 随机排序数组
225
+ * @param arr any[]
226
+ * @example
227
+ * randomSortArr([1,2,3]) => [1,3,2]
228
+ * randomSortArr([{a:1},{a:2},{a:3}]) => [{a:3},{a:1},{a:2}]
229
+ */
230
+ function randomSortArr(arr) {
231
+ var _a;
232
+ return new Array((_a = arr === null || arr === void 0 ? void 0 : arr.length) !== null && _a !== void 0 ? _a : 0).fill(0).map(function (_, i) {
233
+ return i;
234
+ }).sort(function () {
235
+ return Math.random() - 0.5;
236
+ }).map(function (index) {
237
+ return arr[index];
238
+ });
239
+ }
240
+ ArrayUtil.randomSortArr = randomSortArr;
241
+ })(ArrayUtil || (ArrayUtil = {}));
242
+ export default ArrayUtil;
@@ -0,0 +1,158 @@
1
+ /**
2
+ * 树工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 10:31:35
6
+ */
7
+ import { FieldNames, TreeData, ValueType } from '../types';
8
+ declare namespace TreeUtil {
9
+ /**
10
+ * @name 循环树改变原数组
11
+ * @param tree tree数组
12
+ * @param callback 回调(item:当前循环项,parent: 父对象)
13
+ * @param children children字段
14
+ * @param defaultParent 默认上级对象
15
+ *
16
+ */
17
+ function forEachTree<T>(tree: T[], callback: (t: T, p?: T) => void, children?: string, defaultParent?: T): T[];
18
+ /**
19
+ * @name 查找树
20
+ * @param tree tree数组
21
+ * @param callback 回调(item:当前循环项,parent: 父对象)
22
+ * @param children children字段
23
+ * @param defaultParent 默认上级对象
24
+ */
25
+ function findTreeData<T>(tree: T[], callback: (t: T, p?: T) => boolean, children?: string, defaultParent?: T): T | undefined;
26
+ /**
27
+ * @name 筛选树
28
+ * @param tree tree数组
29
+ * @param callback 回调(item:当前循环项,parent: 父对象)
30
+ * @param children children字段
31
+ * @param defaultParent 默认上级对象
32
+ */
33
+ function filterTreeData<T>(tree: T[], callback: (t: T, p?: T) => boolean, children?: string, defaultParent?: T): T[];
34
+ /**
35
+ * @name 列表转树
36
+ * @param list 数组
37
+ * @param fieldNames 映射对象
38
+ */
39
+ function getTreeByList<T>(list: T[], fieldNames?: FieldNames): (T & TreeData)[];
40
+ /**
41
+ * @name 树转列表
42
+ * @param tree 数组
43
+ */
44
+ function getListByTree<T>(tree: T[], children?: string): T[];
45
+ /**
46
+ * @name 获取树中id路径数组
47
+ * @param tree 树
48
+ * @param id 主键
49
+ * @param fieldNames 映射对象
50
+ */
51
+ function getIdPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): ValueType[];
52
+ /**
53
+ * @name 获取树中路径对象数组
54
+ * @param tree 树
55
+ * @param id 主键
56
+ * @param fieldNames 映射对象
57
+ */
58
+ function getItemPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): T[];
59
+ /**
60
+ * @name 字符串分割转为树结构
61
+ * @param str string
62
+ * @param splitStr /
63
+ * @param fieldNames 映射对象
64
+ * @example
65
+ *
66
+ * `一级选项 1/二级选项 1/三级选项 1
67
+ 一级选项 1/二级选项 1/三级选项 2
68
+ 一级选项 2/二级选项 1`
69
+ //转换后
70
+ [
71
+ {
72
+ name: '一级选项 1',
73
+ id: '一级选项 1',
74
+ children: [
75
+ {
76
+ name: '二级选项 1',
77
+ id: '二级选项 1',
78
+ pid: '一级选项 1',
79
+ children: [
80
+ {
81
+ name: '三级选项 1',
82
+ id: '三级选项 1',
83
+ pid: '二级选项 1',
84
+ },
85
+ {
86
+ name: '三级选项 2',
87
+ id: '三级选项 2',
88
+ pid: '二级选项 1',
89
+ },
90
+ ],
91
+ },
92
+ ],
93
+ },
94
+ {
95
+ name: '一级选项 2',
96
+ id: '一级选项 2',
97
+ children: [
98
+ {
99
+ name: '二级选项 1',
100
+ id: '二级选项 1',
101
+ pid: '一级选项 2',
102
+ },
103
+ ],
104
+ },
105
+ ]
106
+ */
107
+ function strSplit2tree(str: string, splitStr?: string, fieldNames?: FieldNames): Record<string, any>[];
108
+ /**
109
+ * @name 树结构转为字符串分割
110
+ * @param tree 树
111
+ * @param splitStr /
112
+ * @param fieldNames 映射对象
113
+ * @example
114
+ *
115
+ * [
116
+ {
117
+ name: '一级选项 1',
118
+ id: '一级选项 1',
119
+ children: [
120
+ {
121
+ name: '二级选项 1',
122
+ id: '二级选项 1',
123
+ pid: '一级选项 1',
124
+ children: [
125
+ {
126
+ name: '三级选项 1',
127
+ id: '三级选项 1',
128
+ pid: '二级选项 1',
129
+ },
130
+ {
131
+ name: '三级选项 2',
132
+ id: '三级选项 2',
133
+ pid: '二级选项 1',
134
+ },
135
+ ],
136
+ },
137
+ ],
138
+ },
139
+ {
140
+ name: '一级选项 2',
141
+ id: '一级选项 2',
142
+ children: [
143
+ {
144
+ name: '二级选项 1',
145
+ id: '二级选项 1',
146
+ pid: '一级选项 2',
147
+ },
148
+ ],
149
+ },
150
+ ]
151
+ //转换后
152
+ `一级选项 1/二级选项 1/三级选项 1
153
+ 一级选项 1/二级选项 1/三级选项 2
154
+ 一级选项 2/二级选项 1`
155
+ */
156
+ function tree2strSplit<T>(tree: T[], splitStr?: string, fieldNames?: FieldNames): string;
157
+ }
158
+ export default TreeUtil;