@etsoo/shared 1.2.54 → 1.2.55
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/__tests__/ArrayUtils.ts +126 -126
- package/__tests__/ColorUtils.ts +24 -24
- package/__tests__/ContentDisposition.ts +18 -18
- package/__tests__/DataTypes.ts +222 -204
- package/__tests__/DateUtils.ts +82 -82
- package/__tests__/DomUtils.ts +352 -352
- package/__tests__/EHistory.ts +62 -62
- package/__tests__/ExtendUtils.ts +40 -40
- package/__tests__/Keyboard.ts +14 -14
- package/__tests__/NumberUtils.ts +37 -39
- package/__tests__/StorageUtils.ts +27 -27
- package/__tests__/Utils.ts +361 -363
- package/__tests__/tsconfig.json +15 -15
- package/package.json +2 -2
package/__tests__/ArrayUtils.ts
CHANGED
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import { ArrayUtils } from
|
|
1
|
+
import { ArrayUtils } from "../src/ArrayUtils";
|
|
2
2
|
|
|
3
|
-
test(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
test("Tests for simple type toUnique", () => {
|
|
4
|
+
const result = [1, 1, 3, 5, 5].toUnique();
|
|
5
|
+
expect(result).toStrictEqual([1, 3, 5]);
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
test(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
test("Tests for object type toUnique", () => {
|
|
9
|
+
const result = [
|
|
10
|
+
{ id: 1, label: "a" },
|
|
11
|
+
{ id: 2, label: "b" },
|
|
12
|
+
{ id: 2, label: "b" }
|
|
13
|
+
].toUnique();
|
|
14
|
+
expect(result.length).toBe(2);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
test(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
test("Tests for differences", () => {
|
|
18
|
+
const a1 = ["a", "b", "c", "e"];
|
|
19
|
+
const a2 = ["a", "c", "d"];
|
|
20
|
+
expect(ArrayUtils.differences(a1, a2)).toEqual(["b", "e"]);
|
|
21
|
+
expect(ArrayUtils.differences(a1, a2, true)).toEqual(["b", "e", "d"]);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
test(
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
test("Tests for sum numbers", () => {
|
|
25
|
+
const items = [12, 8, 22];
|
|
26
|
+
expect(items.sum()).toBe(42);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
test(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
test("Tests for sum fields", () => {
|
|
30
|
+
const items = [
|
|
31
|
+
{ id: 1, label: "a", amount: 3.14 },
|
|
32
|
+
{ id: 2, label: "b", amount: 4.54 }
|
|
33
|
+
];
|
|
34
|
+
expect(items.sum("amount")).toBe(7.68);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
test(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
test("Tests for max / min numbers", () => {
|
|
38
|
+
const items = [12, 8, 22];
|
|
39
|
+
expect(items.max()).toBe(22);
|
|
40
|
+
expect(items.min()).toBe(8);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
test(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
test("Tests for max / min fields", () => {
|
|
44
|
+
const items = [
|
|
45
|
+
{ id: 1, label: "a", amount: 3.14 },
|
|
46
|
+
{ id: 2, label: "b", amount: 4.54 },
|
|
47
|
+
{ id: 3, label: "b", amount: 1.52 }
|
|
48
|
+
];
|
|
49
|
+
expect(items.max("amount")).toBe(4.54);
|
|
50
|
+
expect(items.min("amount")).toBe(1.52);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
test(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
test("Tests for maxItem / minItem", () => {
|
|
54
|
+
const items = [
|
|
55
|
+
{ id: 1, label: "a", amount: 3.14 },
|
|
56
|
+
{ id: 2, label: "b", amount: 4.54 },
|
|
57
|
+
{ id: 3, label: "b", amount: 1.52 }
|
|
58
|
+
];
|
|
59
|
+
expect(items.maxItem("amount")?.id).toBe(2);
|
|
60
|
+
expect(items.minItem("amount")?.id).toBe(3);
|
|
61
|
+
|
|
62
|
+
const emptyItems: { id: string; amount: number }[] = [];
|
|
63
|
+
expect(emptyItems.maxItem("amount")).toBeUndefined();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
test(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
test("Tests for remove simple", () => {
|
|
67
|
+
const items = [1, 2, 3, 4, 5];
|
|
68
|
+
const result = items.remove(1, 5, (item) => item % 2 === 0);
|
|
69
|
+
expect(items).toStrictEqual([3]);
|
|
70
|
+
expect(result.length).toBe(4);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
test(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
73
|
+
test("Tests for remove object", () => {
|
|
74
|
+
const item = { id: 4, label: "d", amount: 9.66 };
|
|
75
|
+
const items = [
|
|
76
|
+
{ id: 1, label: "a", amount: 3.14 },
|
|
77
|
+
{ id: 2, label: "b", amount: 4.54 },
|
|
78
|
+
{ id: 3, label: "b", amount: 1.52 },
|
|
79
|
+
item
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const result = items.remove(
|
|
83
|
+
item,
|
|
84
|
+
(item) => item.id === 2,
|
|
85
|
+
(item) => item.amount <= 2
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(items.length).toBe(1);
|
|
89
|
+
expect(items[0].id).toBe(1);
|
|
90
|
+
expect(result.length).toBe(3);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
test(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
93
|
+
test("Tests for sortIds 1", () => {
|
|
94
|
+
const source = [
|
|
95
|
+
{
|
|
96
|
+
id: "zh-Hans",
|
|
97
|
+
label: "中文(简体), Chinese (Simplified)"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "en",
|
|
101
|
+
label: "英语, English"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: "fr",
|
|
105
|
+
label: "法语, French"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "de",
|
|
109
|
+
label: "德语, German"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "zh-Hant",
|
|
113
|
+
label: "中文(繁体), Chinese (Traditional)"
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
source.sortByProperty("id", ["en", "zh-Hans", "zh-Hant"]);
|
|
117
|
+
|
|
118
|
+
const ids = source.map((s) => s.id);
|
|
119
|
+
expect(ids).toStrictEqual(["en", "zh-Hans", "zh-Hant", "fr", "de"]);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
test(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
122
|
+
test("Tests for sortIds 2", () => {
|
|
123
|
+
const source = [
|
|
124
|
+
{ id: "AUD", label: "澳元" },
|
|
125
|
+
{ id: "CAD", label: "加元" },
|
|
126
|
+
{ id: "CNY", label: "人民币" },
|
|
127
|
+
{ id: "EUR", label: "欧元" },
|
|
128
|
+
{ id: "GBP", label: "英镑" },
|
|
129
|
+
{ id: "HKD", label: "港币" },
|
|
130
|
+
{ id: "JPY", label: "日元" },
|
|
131
|
+
{ id: "NZD", label: "纽币" },
|
|
132
|
+
{ id: "SGD", label: "新币" },
|
|
133
|
+
{ id: "USD", label: "美元" }
|
|
134
|
+
];
|
|
135
|
+
source.sortByProperty("id", ["USD", "CNY"]);
|
|
136
|
+
|
|
137
|
+
const ids = source.map((s) => s.id);
|
|
138
|
+
expect(ids).toStrictEqual([
|
|
139
|
+
"USD",
|
|
140
|
+
"CNY",
|
|
141
|
+
"AUD",
|
|
142
|
+
"CAD",
|
|
143
|
+
"EUR",
|
|
144
|
+
"GBP",
|
|
145
|
+
"HKD",
|
|
146
|
+
"JPY",
|
|
147
|
+
"NZD",
|
|
148
|
+
"SGD"
|
|
149
|
+
]);
|
|
150
150
|
});
|
package/__tests__/ColorUtils.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { EColor } from
|
|
2
|
-
import { ColorUtils } from
|
|
1
|
+
import { EColor } from "../src/types/EColor";
|
|
2
|
+
import { ColorUtils } from "../src/ColorUtils";
|
|
3
3
|
|
|
4
|
-
test(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
test("Tests for format", () => {
|
|
5
|
+
expect(EColor.format("transparent")).toBe("transparent");
|
|
6
|
+
expect(EColor.format("RED")).toBe("red");
|
|
7
|
+
expect(EColor.format("RGB(226, 24, 33)", true)).toBe("#e21821");
|
|
8
|
+
expect(EColor.format("RGB(226, 24, 33)")).toBe("RGB(226, 24, 33)");
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
test(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
test("Tests for parse", () => {
|
|
12
|
+
// Arrange & act
|
|
13
|
+
const colorShort = EColor.parse("#000");
|
|
14
|
+
const color = EColor.parse("#e21821");
|
|
15
|
+
const colorRgb = EColor.parse("RGB(226, 24, 33)");
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// Assert
|
|
18
|
+
expect(colorShort?.toRGBColor()).toBe("RGB(0, 0, 0)");
|
|
19
|
+
expect(color?.toRGBColor()).toBe("RGB(226, 24, 33)");
|
|
20
|
+
expect(colorRgb?.toHEXColor()).toBe("#e21821");
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
test(
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
test("Tests for getColors", () => {
|
|
24
|
+
const colors = ColorUtils.getColors(undefined, 128);
|
|
25
|
+
expect(colors.length).toBe(8);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
test(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
test("Tests for toRGBColor", () => {
|
|
29
|
+
const color = new EColor(0, 0, 0);
|
|
30
|
+
expect(color.toRGBColor()).toBe("RGB(0, 0, 0)");
|
|
31
|
+
expect(color.toRGBColor(0.1)).toBe("RGBA(0, 0, 0, 0.1)");
|
|
32
|
+
expect(color.alpha).toBeUndefined();
|
|
33
33
|
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { ContentDisposition } from
|
|
1
|
+
import { ContentDisposition } from "../src/types/ContentDisposition";
|
|
2
2
|
|
|
3
|
-
test(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
test("Tests for parse", () => {
|
|
4
|
+
const cd1 = ContentDisposition.parse(
|
|
5
|
+
"attachment; filename=__PDF.pdf; filename*=UTF-8''%E6%B5%8B%E8%AF%95PDF.pdf"
|
|
6
|
+
);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const cd2 = ContentDisposition.parse(
|
|
9
|
+
`attachment; filename="__PDF.pdf"; filename*="UTF-8''%E6%B5%8B%E8%AF%95PDF.pdf"`
|
|
10
|
+
);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
expect(cd1?.type).toBe(cd2?.type);
|
|
13
|
+
expect(cd1?.filename).toBe(cd2?.filename);
|
|
14
|
+
expect(cd1?.filename).toBe("测试PDF.pdf");
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
test(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
test("Tests for format", () => {
|
|
18
|
+
const cd1 = new ContentDisposition("form-data", "a-b.jpg", "file");
|
|
19
|
+
expect(cd1.format()).toBe(`form-data; name="file"; filename="a-b.jpg"`);
|
|
20
|
+
const cd2 = new ContentDisposition("attachment", "测试PDF.pdf");
|
|
21
|
+
expect(cd2.format()).toBe(
|
|
22
|
+
`attachment; filename="__PDF.pdf"; filename*="UTF-8''%E6%B5%8B%E8%AF%95PDF.pdf"`
|
|
23
|
+
);
|
|
24
24
|
});
|