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