@whitesev/utils 2.9.2 → 2.9.4

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.
@@ -4216,9 +4216,35 @@ System.register('Utils', [], (function (exports) {
4216
4216
 
4217
4217
  class UtilsDictionary {
4218
4218
  items;
4219
- constructor(key, value) {
4219
+ constructor(...args) {
4220
4220
  this.items = new Map();
4221
- if (key != null) {
4221
+ if (args.length === 1) {
4222
+ // 数组|对象
4223
+ const data = args[0];
4224
+ if (Array.isArray(data)) {
4225
+ // 数组
4226
+ // [[1,2], [3,4], ...]
4227
+ for (let index = 0; index < data.length; index++) {
4228
+ const item = data[index];
4229
+ if (Array.isArray(item)) {
4230
+ const [key, value] = item;
4231
+ this.set(key, value);
4232
+ }
4233
+ }
4234
+ }
4235
+ else if (typeof data === "object" && data != null) {
4236
+ // 对象
4237
+ // {1:2, 3:4}
4238
+ for (const key in data) {
4239
+ if (Reflect.has(data, key)) {
4240
+ this.set(key, data[key]);
4241
+ }
4242
+ }
4243
+ }
4244
+ }
4245
+ else if (args.length === 2) {
4246
+ // 键、值
4247
+ const [key, value] = args;
4222
4248
  this.set(key, value);
4223
4249
  }
4224
4250
  }
@@ -4234,7 +4260,7 @@ System.register('Utils', [], (function (exports) {
4234
4260
  get entries() {
4235
4261
  const that = this;
4236
4262
  return function* () {
4237
- const itemKeys = Object.keys(that.getItems());
4263
+ const itemKeys = that.keys();
4238
4264
  for (const keyName of itemKeys) {
4239
4265
  yield [keyName, that.get(keyName)];
4240
4266
  }
@@ -4271,7 +4297,7 @@ System.register('Utils', [], (function (exports) {
4271
4297
  */
4272
4298
  set(key, val) {
4273
4299
  if (key === void 0) {
4274
- throw new Error("Utils.Dictionary().set 参数 key 不能为空");
4300
+ throw new Error("Utils.Dictionary().set 参数 key 不能为undefined");
4275
4301
  }
4276
4302
  this.items.set(key, val);
4277
4303
  }
@@ -5477,7 +5503,7 @@ System.register('Utils', [], (function (exports) {
5477
5503
  }
5478
5504
  const domUtils = new DOMUtils();
5479
5505
 
5480
- const version = "2.9.2";
5506
+ const version = "2.9.4";
5481
5507
 
5482
5508
  class Utils {
5483
5509
  windowApi;
@@ -7637,30 +7663,34 @@ System.register('Utils', [], (function (exports) {
7637
7663
  });
7638
7664
  }
7639
7665
  }
7640
- sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
7666
+ sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
7641
7667
  const that = this;
7642
- if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
7668
+ if (typeof getComparePropertyValue !== "function" && typeof getComparePropertyValue !== "string") {
7643
7669
  throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
7644
7670
  }
7645
7671
  if (typeof sortByDesc !== "boolean") {
7646
7672
  throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
7647
7673
  }
7648
- const getObjValue = function (obj) {
7649
- return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
7674
+ const getTargetValue = function (target) {
7675
+ return typeof getComparePropertyValue === "string"
7676
+ ? target[getComparePropertyValue]
7677
+ : getComparePropertyValue(target);
7650
7678
  };
7651
7679
  /**
7652
- * 排序方法
7653
- * @param after_obj
7654
- * @param before_obj
7680
+ * number类型排序方法
7681
+ * @param afterInst
7682
+ * @param beforeInst
7655
7683
  */
7656
- const sortFunc = function (after_obj, before_obj) {
7657
- const beforeValue = getObjValue(before_obj); /* 前 */
7658
- const afterValue = getObjValue(after_obj); /* 后 */
7684
+ const sortFunc = function (afterInst, beforeInst) {
7685
+ const beforeValue = getTargetValue(beforeInst); /* 前 */
7686
+ const afterValue = getTargetValue(afterInst); /* 后 */
7659
7687
  if (sortByDesc) {
7660
- if (afterValue > beforeValue) {
7688
+ // 降序
7689
+ // 5、4、3、2、1
7690
+ if (beforeValue < afterValue) {
7661
7691
  return -1;
7662
7692
  }
7663
- else if (afterValue < beforeValue) {
7693
+ else if (beforeValue > afterValue) {
7664
7694
  return 1;
7665
7695
  }
7666
7696
  else {
@@ -7668,10 +7698,12 @@ System.register('Utils', [], (function (exports) {
7668
7698
  }
7669
7699
  }
7670
7700
  else {
7671
- if (afterValue < beforeValue) {
7701
+ // 升序
7702
+ // 1、2、3、4、5
7703
+ if (beforeValue > afterValue) {
7672
7704
  return -1;
7673
7705
  }
7674
- else if (afterValue > beforeValue) {
7706
+ else if (beforeValue < afterValue) {
7675
7707
  return 1;
7676
7708
  }
7677
7709
  else {
@@ -7680,18 +7712,18 @@ System.register('Utils', [], (function (exports) {
7680
7712
  }
7681
7713
  };
7682
7714
  /**
7683
- * 排序元素方法
7715
+ * 元素排序方法
7684
7716
  * @param nodeList 元素列表
7685
7717
  * @param getNodeListFunc 获取元素列表的函数
7686
7718
  */
7687
7719
  const sortNodeFunc = function (nodeList, getNodeListFunc) {
7688
7720
  const nodeListLength = nodeList.length;
7689
- for (let i = 0; i < nodeListLength - 1; i++) {
7690
- for (let j = 0; j < nodeListLength - 1 - i; j++) {
7691
- const beforeNode = nodeList[j];
7692
- const afterNode = nodeList[j + 1];
7693
- const beforeValue = getObjValue(beforeNode); /* 前 */
7694
- const afterValue = getObjValue(afterNode); /* 后 */
7721
+ for (let index = 0; index < nodeListLength - 1; index++) {
7722
+ for (let index2 = 0; index2 < nodeListLength - 1 - index; index2++) {
7723
+ const beforeNode = nodeList[index2];
7724
+ const afterNode = nodeList[index2 + 1];
7725
+ const beforeValue = getTargetValue(beforeNode); /* 前 */
7726
+ const afterValue = getTargetValue(afterNode); /* 后 */
7695
7727
  if ((sortByDesc == true && beforeValue < afterValue) || (sortByDesc == false && beforeValue > afterValue)) {
7696
7728
  /* 升序/降序 */
7697
7729
  /* 相邻元素两两对比 */
@@ -7714,7 +7746,9 @@ System.register('Utils', [], (function (exports) {
7714
7746
  let getDataFunc = null;
7715
7747
  if (data instanceof Function) {
7716
7748
  getDataFunc = data;
7717
- data = data();
7749
+ const newData = getDataFunc();
7750
+ data = newData;
7751
+ result = newData;
7718
7752
  }
7719
7753
  if (Array.isArray(data)) {
7720
7754
  data.sort(sortFunc);