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