@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.iife.js
CHANGED
|
@@ -4214,9 +4214,35 @@ var Utils = (function () {
|
|
|
4214
4214
|
|
|
4215
4215
|
class UtilsDictionary {
|
|
4216
4216
|
items;
|
|
4217
|
-
constructor(
|
|
4217
|
+
constructor(...args) {
|
|
4218
4218
|
this.items = new Map();
|
|
4219
|
-
if (
|
|
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 =
|
|
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.
|
|
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,
|
|
7664
|
+
sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
|
|
7639
7665
|
const that = this;
|
|
7640
|
-
if (typeof
|
|
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
|
|
7647
|
-
return typeof
|
|
7672
|
+
const getTargetValue = function (target) {
|
|
7673
|
+
return typeof getComparePropertyValue === "string"
|
|
7674
|
+
? target[getComparePropertyValue]
|
|
7675
|
+
: getComparePropertyValue(target);
|
|
7648
7676
|
};
|
|
7649
7677
|
/**
|
|
7650
|
-
*
|
|
7651
|
-
* @param
|
|
7652
|
-
* @param
|
|
7678
|
+
* number类型排序方法
|
|
7679
|
+
* @param afterInst
|
|
7680
|
+
* @param beforeInst
|
|
7653
7681
|
*/
|
|
7654
|
-
const sortFunc = function (
|
|
7655
|
-
const beforeValue =
|
|
7656
|
-
const afterValue =
|
|
7682
|
+
const sortFunc = function (afterInst, beforeInst) {
|
|
7683
|
+
const beforeValue = getTargetValue(beforeInst); /* 前 */
|
|
7684
|
+
const afterValue = getTargetValue(afterInst); /* 后 */
|
|
7657
7685
|
if (sortByDesc) {
|
|
7658
|
-
|
|
7686
|
+
// 降序
|
|
7687
|
+
// 5、4、3、2、1
|
|
7688
|
+
if (beforeValue < afterValue) {
|
|
7659
7689
|
return -1;
|
|
7660
7690
|
}
|
|
7661
|
-
else if (
|
|
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
|
-
|
|
7699
|
+
// 升序
|
|
7700
|
+
// 1、2、3、4、5
|
|
7701
|
+
if (beforeValue > afterValue) {
|
|
7670
7702
|
return -1;
|
|
7671
7703
|
}
|
|
7672
|
-
else if (
|
|
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
|
|
7688
|
-
for (let
|
|
7689
|
-
const beforeNode = nodeList[
|
|
7690
|
-
const afterNode = nodeList[
|
|
7691
|
-
const beforeValue =
|
|
7692
|
-
const afterValue =
|
|
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
|
-
|
|
7747
|
+
const newData = getDataFunc();
|
|
7748
|
+
data = newData;
|
|
7749
|
+
result = newData;
|
|
7716
7750
|
}
|
|
7717
7751
|
if (Array.isArray(data)) {
|
|
7718
7752
|
data.sort(sortFunc);
|