@etsoo/shared 1.2.52 → 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/.github/workflows/main.yml +6 -5
- 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/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +1 -1
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +1 -1
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +42 -42
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
name: Node.js Package
|
|
7
7
|
|
|
8
8
|
# Event to trigger the action
|
|
9
|
-
on:
|
|
9
|
+
on:
|
|
10
|
+
[push]
|
|
10
11
|
# release:
|
|
11
12
|
# types: [created]
|
|
12
13
|
|
|
@@ -23,13 +24,13 @@ jobs:
|
|
|
23
24
|
# https://github.com/actions/checkout, This action checks-out your repository under $GITHUB_WORKSPACE
|
|
24
25
|
# so your workflow can access it.
|
|
25
26
|
- uses: actions/checkout@v4
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
# Set up your GitHub Actions workflow with a specific version of node.js
|
|
28
29
|
# Setup .npmrc file to publish to npm
|
|
29
30
|
- uses: actions/setup-node@v4
|
|
30
31
|
with:
|
|
31
|
-
node-version:
|
|
32
|
-
registry-url:
|
|
32
|
+
node-version: "latest"
|
|
33
|
+
registry-url: "https://registry.npmjs.org"
|
|
33
34
|
|
|
34
35
|
# Named after Continuous Integration, installs dependencies directly from package-lock.json
|
|
35
36
|
# ci vs install
|
|
@@ -45,4 +46,4 @@ jobs:
|
|
|
45
46
|
# For scoped package, make it public for free service
|
|
46
47
|
- run: npm publish --access public
|
|
47
48
|
env:
|
|
48
|
-
NODE_AUTH_TOKEN: ${{ secrets.ETSOONpmToken }}
|
|
49
|
+
NODE_AUTH_TOKEN: ${{ secrets.ETSOONpmToken }}
|
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
|
});
|