@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.system.js
CHANGED
|
@@ -4216,9 +4216,35 @@ System.register('Utils', [], (function (exports) {
|
|
|
4216
4216
|
|
|
4217
4217
|
class UtilsDictionary {
|
|
4218
4218
|
items;
|
|
4219
|
-
constructor(
|
|
4219
|
+
constructor(...args) {
|
|
4220
4220
|
this.items = new Map();
|
|
4221
|
-
if (
|
|
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 =
|
|
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.
|
|
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,
|
|
7666
|
+
sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
|
|
7641
7667
|
const that = this;
|
|
7642
|
-
if (typeof
|
|
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
|
|
7649
|
-
return typeof
|
|
7674
|
+
const getTargetValue = function (target) {
|
|
7675
|
+
return typeof getComparePropertyValue === "string"
|
|
7676
|
+
? target[getComparePropertyValue]
|
|
7677
|
+
: getComparePropertyValue(target);
|
|
7650
7678
|
};
|
|
7651
7679
|
/**
|
|
7652
|
-
*
|
|
7653
|
-
* @param
|
|
7654
|
-
* @param
|
|
7680
|
+
* number类型排序方法
|
|
7681
|
+
* @param afterInst
|
|
7682
|
+
* @param beforeInst
|
|
7655
7683
|
*/
|
|
7656
|
-
const sortFunc = function (
|
|
7657
|
-
const beforeValue =
|
|
7658
|
-
const afterValue =
|
|
7684
|
+
const sortFunc = function (afterInst, beforeInst) {
|
|
7685
|
+
const beforeValue = getTargetValue(beforeInst); /* 前 */
|
|
7686
|
+
const afterValue = getTargetValue(afterInst); /* 后 */
|
|
7659
7687
|
if (sortByDesc) {
|
|
7660
|
-
|
|
7688
|
+
// 降序
|
|
7689
|
+
// 5、4、3、2、1
|
|
7690
|
+
if (beforeValue < afterValue) {
|
|
7661
7691
|
return -1;
|
|
7662
7692
|
}
|
|
7663
|
-
else if (
|
|
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
|
-
|
|
7701
|
+
// 升序
|
|
7702
|
+
// 1、2、3、4、5
|
|
7703
|
+
if (beforeValue > afterValue) {
|
|
7672
7704
|
return -1;
|
|
7673
7705
|
}
|
|
7674
|
-
else if (
|
|
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
|
|
7690
|
-
for (let
|
|
7691
|
-
const beforeNode = nodeList[
|
|
7692
|
-
const afterNode = nodeList[
|
|
7693
|
-
const beforeValue =
|
|
7694
|
-
const afterValue =
|
|
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
|
-
|
|
7749
|
+
const newData = getDataFunc();
|
|
7750
|
+
data = newData;
|
|
7751
|
+
result = newData;
|
|
7718
7752
|
}
|
|
7719
7753
|
if (Array.isArray(data)) {
|
|
7720
7754
|
data.sort(sortFunc);
|