qmwts 1.1.39 → 1.1.41

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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import ArrayUtils from './utils/array-utils';
1
2
  import Downloader from './utils/downloader';
2
3
  import NumberUtils from './utils/number-utils';
3
4
  import JsonUtils from './utils/json-utils';
@@ -9,4 +10,4 @@ import DateUtils from './utils/date-utils';
9
10
  import LocalDate from './class/local-date';
10
11
  import LocalDateTime from './class/local-date-time';
11
12
  import YearMonth from './class/year-month';
12
- export { Downloader, NumberUtils, JsonUtils, UUIDUtils, PrototypeUtils, RequestDataGenerator, FileUtils, DateUtils, LocalDate, LocalDateTime, YearMonth, };
13
+ export { ArrayUtils, Downloader, NumberUtils, JsonUtils, UUIDUtils, PrototypeUtils, RequestDataGenerator, FileUtils, DateUtils, LocalDate, LocalDateTime, YearMonth, };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.DateUtils = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = exports.Downloader = void 0;
3
+ exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.DateUtils = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = exports.Downloader = exports.ArrayUtils = void 0;
4
4
  // https://www.jianshu.com/p/8fa2c50720e4
5
+ var array_utils_1 = require("./utils/array-utils");
6
+ exports.ArrayUtils = array_utils_1.default;
5
7
  var downloader_1 = require("./utils/downloader");
6
8
  exports.Downloader = downloader_1.default;
7
9
  var number_utils_1 = require("./utils/number-utils");
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ /**
3
+ * 数组转化为树形结构
4
+ * @param array 数组
5
+ * @param idKey id
6
+ * @param parentKey 关联上级字段
7
+ * @param childrenKey 下级字段
8
+ */
9
+ listToTree<T>(array?: any[], idKey?: string, parentKey?: string, childrenKey?: string): T[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ /**
5
+ * 数组转化为树形结构
6
+ * @param array 数组
7
+ * @param idKey id
8
+ * @param parentKey 关联上级字段
9
+ * @param childrenKey 下级字段
10
+ */
11
+ listToTree: function (array, idKey, parentKey, childrenKey) {
12
+ if (array === void 0) { array = []; }
13
+ if (idKey === void 0) { idKey = 'id'; }
14
+ if (parentKey === void 0) { parentKey = 'parentId'; }
15
+ if (childrenKey === void 0) { childrenKey = 'children'; }
16
+ var map = new Map(); // 先根据每项的parentId将该项放入Map
17
+ for (var i = array.length - 1; i >= 0; i--) {
18
+ var e = array[i], _a = e, _b = parentKey, pid = _a[_b];
19
+ var children = map.get(pid) || [];
20
+ children.unshift(e);
21
+ }
22
+ var o = [];
23
+ for (var i = array.length - 1; i >= 0; i--) {
24
+ var e = array[i], _c = e, _d = idKey, id = _c[_d], _e = parentKey, pid = _c[_e];
25
+ e[childrenKey] = map.get(id); // 赋值children
26
+ if (!pid) // 只返回最上级
27
+ o.unshift(e);
28
+ }
29
+ return o;
30
+ }
31
+ };
@@ -13,4 +13,5 @@ Promise.resolve().then(function () {
13
13
  console.log(3);
14
14
  }).then(function () {
15
15
  console.log(5);
16
+ console.log(6);
16
17
  });
@@ -45,7 +45,7 @@ exports.default = {
45
45
  o = '';
46
46
  }
47
47
  }
48
- if (o === void 0 || o === null)
48
+ if ([void 0, null].includes(o))
49
49
  return substitute;
50
50
  return o;
51
51
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.1.39",
3
+ "version": "1.1.41",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",