@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
package/__tests__/DataTypes.ts
CHANGED
|
@@ -1,218 +1,236 @@
|
|
|
1
|
-
import { DataTypes, IdDefaultType, LabelDefaultType } from
|
|
2
|
-
|
|
3
|
-
test(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { DataTypes, IdDefaultType, LabelDefaultType } from "../src/DataTypes";
|
|
2
|
+
|
|
3
|
+
test("Tests for DI", () => {
|
|
4
|
+
const item: DataTypes.DIS<"id", number> & DataTypes.DIS<"label", string> = {
|
|
5
|
+
id: 1,
|
|
6
|
+
label: "Etsoo"
|
|
7
|
+
};
|
|
8
|
+
expect(item.id).toBe(1);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("Tests for IdLabelType", () => {
|
|
12
|
+
const item: DataTypes.IdLabelItem = {
|
|
13
|
+
id: 1,
|
|
14
|
+
label: "Etsoo"
|
|
15
|
+
};
|
|
16
|
+
const itemCopy: DataTypes.IdLabelType<"id", "label"> = { ...item };
|
|
17
|
+
expect(item).toEqual(itemCopy);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
test(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
test("Tests for Bigint Type", () => {
|
|
21
|
+
type BigintType = {
|
|
22
|
+
id: bigint;
|
|
23
|
+
label: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const item: BigintType = {
|
|
27
|
+
id: 9007199254740999n,
|
|
28
|
+
label: "Etsoo"
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const json = JSON.stringify(item);
|
|
32
|
+
expect(json).toBe('{"id":"9007199254740999n","label":"Etsoo"}');
|
|
33
|
+
|
|
34
|
+
const itemBack = JSON.parse(
|
|
35
|
+
json,
|
|
36
|
+
DataTypes.jsonBigintReceiver("id")
|
|
37
|
+
) as BigintType;
|
|
38
|
+
expect(itemBack.id).toBe(9007199254740999n);
|
|
39
39
|
});
|
|
40
|
-
|
|
41
|
-
test(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
|
|
41
|
+
test("Tests for convert", () => {
|
|
42
|
+
expect(DataTypes.convert("5", 0)).toStrictEqual(5);
|
|
43
|
+
expect(DataTypes.convert("2021/10/13", new Date())?.getDate()).toStrictEqual(
|
|
44
|
+
13
|
|
45
|
+
);
|
|
46
|
+
expect(DataTypes.convert("a", [])?.length).toStrictEqual(1);
|
|
47
|
+
expect(DataTypes.convert("1", [0])).toStrictEqual([1]);
|
|
48
|
+
expect(DataTypes.convert("", 0)).toBeUndefined();
|
|
49
|
+
expect(DataTypes.convert("false", true)).toBeFalsy();
|
|
50
|
+
expect(DataTypes.convert("1", true)).toBeTruthy();
|
|
51
|
+
expect(DataTypes.convert(true, true)).toBeTruthy();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
test(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
test("Tests for convertByType", () => {
|
|
55
|
+
expect(DataTypes.convertByType("", "number")).toBeUndefined();
|
|
56
|
+
expect(DataTypes.convertByType("", "string")).toBeUndefined();
|
|
57
|
+
expect(DataTypes.convertByType("", "boolean")).toBeUndefined();
|
|
58
|
+
expect(DataTypes.convertByType(["5", 8], "number[]")).toStrictEqual([5, 8]);
|
|
59
|
+
expect(DataTypes.convertByType(["5", 8], "string[]")).toStrictEqual([
|
|
60
|
+
"5",
|
|
61
|
+
"8"
|
|
62
|
+
]);
|
|
63
|
+
expect(
|
|
64
|
+
DataTypes.convertByType("2021/10/13", "date")?.getDate()
|
|
65
|
+
).toStrictEqual(13);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
test(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
test("Tests for convertSimple", () => {
|
|
69
|
+
expect(
|
|
70
|
+
DataTypes.convertSimple(5.8, DataTypes.CombinedEnum.Int)
|
|
71
|
+
).toStrictEqual(6);
|
|
72
|
+
expect(
|
|
73
|
+
DataTypes.convertSimple(5.88293, DataTypes.CombinedEnum.Money)
|
|
74
|
+
).toStrictEqual(5.8829);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("Tests for getBasicName", () => {
|
|
78
|
+
expect(DataTypes.getBasicName(DataTypes.CombinedEnum.DateTime)).toStrictEqual(
|
|
79
|
+
"date"
|
|
80
|
+
);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
test(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
test(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
83
|
+
test("Tests for getEnumByKey", () => {
|
|
84
|
+
expect(DataTypes.getEnumByKey(DataTypes.HAlignEnum, "Center")).toStrictEqual(
|
|
85
|
+
DataTypes.HAlignEnum.Center
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(
|
|
89
|
+
DataTypes.getEnumByKey(DataTypes.HAlignEnum, "Unknown")
|
|
90
|
+
).toBeUndefined();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("Tests for getEnumByValue", () => {
|
|
94
|
+
expect(DataTypes.getEnumByValue(DataTypes.HAlignEnum, 2)).toStrictEqual(
|
|
95
|
+
DataTypes.HAlignEnum.Center
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(DataTypes.getEnumByValue(DataTypes.HAlignEnum, 4)).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("Tests for getEnumKey", () => {
|
|
102
|
+
expect(
|
|
103
|
+
DataTypes.getEnumKey(DataTypes.HAlignEnum, DataTypes.HAlignEnum.Center)
|
|
104
|
+
).toBe("Center");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("Tests for getEnumKeys", () => {
|
|
108
|
+
enum ProductUnit {
|
|
109
|
+
KILOGRAM = 32,
|
|
110
|
+
GRAM = "GRAM33"
|
|
111
|
+
}
|
|
112
|
+
expect(DataTypes.getEnumKeys(ProductUnit)).toContainEqual("GRAM");
|
|
113
|
+
|
|
114
|
+
const keys = DataTypes.getEnumKeys(DataTypes.CombinedEnum);
|
|
115
|
+
expect(keys).toContainEqual("Unkwown");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("Tests for IdLabelItem", () => {
|
|
119
|
+
// Arrange
|
|
120
|
+
const items: DataTypes.IdLabelItem[] = [
|
|
121
|
+
{ id: 1, label: "Item 1" },
|
|
122
|
+
{ id: 2, label: "Item 2" }
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
// Assert
|
|
126
|
+
expect(items[0].id).toBe(1);
|
|
127
|
+
expect(items[1].label).toBe("Item 2");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("Tests for getValue", () => {
|
|
131
|
+
const data = { id: 1, flag: true };
|
|
132
|
+
expect(DataTypes.getValue(data, "id")).toBe(1);
|
|
133
|
+
expect(DataTypes.getValue(data, "flag")).toBeTruthy();
|
|
134
|
+
expect(DataTypes.getValue(data, "unknown")).toBeUndefined();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("Tests for getIdValue", () => {
|
|
138
|
+
const data = { id: 1, flag: true, field: "string" };
|
|
139
|
+
expect(DataTypes.getIdValue(data, "id")).toBe(1);
|
|
140
|
+
expect(DataTypes.getIdValue(data, "field")).toBe("string");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("Tests for getStringValue", () => {
|
|
144
|
+
const data = { id: 1, flag: true };
|
|
145
|
+
expect(DataTypes.getStringValue(data, "id")).toBe("1");
|
|
146
|
+
expect(DataTypes.getStringValue(data, "flag")).toBe("true");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("Tests for isSimpleType", () => {
|
|
150
|
+
expect(DataTypes.isSimpleType(1)).toBeTruthy();
|
|
151
|
+
expect(DataTypes.isSimpleType(new Date())).toBeTruthy();
|
|
152
|
+
expect(DataTypes.isSimpleType(Symbol())).toBeFalsy();
|
|
153
|
+
expect(DataTypes.isSimpleType(["a", "b", "c"])).toBeTruthy();
|
|
154
|
+
expect(DataTypes.isSimpleType({})).toBeFalsy();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("Tests for IdDefaultType", () => {
|
|
158
|
+
const test = <T extends object, F extends keyof T = IdDefaultType<T>>(
|
|
159
|
+
obj: T,
|
|
160
|
+
field?: F
|
|
161
|
+
) => {
|
|
162
|
+
const f = field ?? ("id" as F);
|
|
163
|
+
return obj[f];
|
|
164
|
+
};
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
type D = { label: string; name: string; id: number };
|
|
167
|
+
const data: D = {
|
|
168
|
+
label: "label",
|
|
169
|
+
name: "name",
|
|
170
|
+
id: 1
|
|
171
|
+
};
|
|
172
|
+
const v = test<D>(data);
|
|
173
|
+
expect(typeof v).toBe("number");
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test(
|
|
180
|
-
|
|
175
|
+
const v1 = test<D, LabelDefaultType<D>>(data, "label");
|
|
176
|
+
expect(v1).toBe("label");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("Tests for jsonReplacer", () => {
|
|
180
|
+
const obj = { a: 1, b: "hello", c: { c1: "C1", c2: false, c3: 128 } };
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
182
|
+
const json1 = JSON.stringify(
|
|
183
|
+
obj,
|
|
184
|
+
DataTypes.jsonReplacer(function (key, value, path) {
|
|
185
|
+
if (["", "a"].includes(key)) {
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
expect(json1).toBe('{"a":1}');
|
|
192
|
+
|
|
193
|
+
const json2 = JSON.stringify(
|
|
194
|
+
obj,
|
|
195
|
+
DataTypes.jsonReplacer(function (key, value, path) {
|
|
196
|
+
if (["", "c"].includes(key) || path === "c.c2") {
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
return undefined;
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
expect(json2).toBe('{"c":{"c2":false}}');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("Tests for AddAndEditType", () => {
|
|
206
|
+
type Entity = DataTypes.AddAndEditType<{
|
|
207
|
+
id: number;
|
|
208
|
+
name: string;
|
|
209
|
+
age?: number;
|
|
210
|
+
}>;
|
|
211
|
+
|
|
212
|
+
const data1: Entity = { id: 1, name: "hello", changedFields: ["name"] };
|
|
213
|
+
const data2: Entity = { id: undefined, name: "hello" };
|
|
214
|
+
const data3: Entity = { name: "hello" };
|
|
215
|
+
|
|
216
|
+
expect(data1.name).toBe(data2.name);
|
|
217
|
+
expect(data2.name).toBe(data3.name);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("Tests for BasicTemplate", () => {
|
|
221
|
+
const template: DataTypes.BasicTemplate = {
|
|
222
|
+
id: "number",
|
|
223
|
+
name: "string",
|
|
224
|
+
birthday: "date"
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const data: { currentPage?: number } & DataTypes.BasicTemplateType<
|
|
228
|
+
typeof template
|
|
229
|
+
> = {
|
|
230
|
+
id: 1,
|
|
231
|
+
name: "Etsoo",
|
|
232
|
+
birthday: new Date()
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
expect(data.id).toBe(1);
|
|
218
236
|
});
|
package/__tests__/DateUtils.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { DateUtils } from
|
|
1
|
+
import { DateUtils } from "../src/DateUtils";
|
|
2
2
|
|
|
3
|
-
test(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
test("Tests for local date time", () => {
|
|
4
|
+
// Arrange
|
|
5
|
+
const date = new Date("2021-06-12T02:23:06");
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// Act & assert
|
|
8
|
+
expect(DateUtils.format(date, "zh-CN", "d")).toBe("2021/06/12");
|
|
9
|
+
expect(DateUtils.format(date, "en-US", "dm")).toBe("06/12/2021 02:23");
|
|
10
|
+
expect(DateUtils.format(date, "en-NZ", "ds")).toBe("12/06/2021 02:23:06");
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
test(
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
test("Tests for UTC date time", () => {
|
|
14
|
+
// Arrange
|
|
15
|
+
const utc1 = new Date("2021-06-12T02:23:06.000Z");
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// Act & assert
|
|
18
|
+
expect(DateUtils.format(utc1, "en-NZ", "ds", "Pacific/Auckland")).toBe(
|
|
19
|
+
"12/06/2021 14:23:06"
|
|
20
|
+
);
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const utc2 = new Date("2021-06-12T02:23:06.000Z");
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
expect(DateUtils.format(utc2, "en-US", "ds", "America/New_York")).toBe(
|
|
25
|
+
"06/11/2021 22:23:06"
|
|
26
|
+
);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
test(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
test("Tests for getDays", () => {
|
|
30
|
+
expect(DateUtils.getDays(2021, 1)).toBe(28);
|
|
31
|
+
expect(DateUtils.getDays(2009, 1)).toBe(28);
|
|
32
|
+
expect(DateUtils.getDays(2008, 1)).toBe(29);
|
|
33
|
+
expect(DateUtils.getDays(2000, 1)).toBe(29);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
test(
|
|
37
|
-
|
|
36
|
+
test("Tests for date parse", () => {
|
|
37
|
+
const json = `
|
|
38
38
|
{
|
|
39
39
|
"id": 1234,
|
|
40
40
|
"logined": false,
|
|
@@ -44,81 +44,81 @@ test('Tests for date parse', () => {
|
|
|
44
44
|
}
|
|
45
45
|
`;
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const result = JSON.parse(json, DateUtils.jsonParser(["creation"]));
|
|
48
|
+
const isDate = result.creation instanceof Date;
|
|
49
|
+
const isIdDate = result.externalId instanceof Date;
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
expect(isIdDate).toBeFalsy();
|
|
52
|
+
expect(isDate).toBeTruthy();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
test(
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
test("Tests for formatForInput", () => {
|
|
56
|
+
const result1 = DateUtils.formatForInput("2021/7/17");
|
|
57
|
+
expect(result1).toBe("2021-07-17");
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const d = new Date(2021, 5, 6, 20, 8, 45);
|
|
60
|
+
const result2 = DateUtils.formatForInput(d);
|
|
61
|
+
expect(result2).toBe("2021-06-06");
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const result3 = DateUtils.formatForInput(d, false);
|
|
64
|
+
expect(result3).toBe("2021-06-06T20:08");
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const result31 = DateUtils.formatForInput(d, "date");
|
|
67
|
+
expect(result31).toBe("2021-06-06");
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const result4 = DateUtils.formatForInput(d, true);
|
|
70
|
+
expect(result4).toBe("2021-06-06T20:08:45");
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const result41 = DateUtils.formatForInput(d, "datetime-local");
|
|
73
|
+
expect(result41).toBe("2021-06-06T20:08:45");
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const result5 = DateUtils.formatForInput("");
|
|
76
|
+
expect(result5).toBeUndefined();
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const result51 = DateUtils.formatForInput(null);
|
|
79
|
+
expect(result51).toBeUndefined();
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
test(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
test("Tests for isExpired", () => {
|
|
83
|
+
expect(DateUtils.isExpired(null)).toBeFalsy();
|
|
84
|
+
expect(DateUtils.isExpired("2020/1/1")).toBeTruthy();
|
|
85
|
+
expect(DateUtils.isExpired("9999/1/1")).toBeFalsy();
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
test(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
test("Tests for substract", () => {
|
|
89
|
+
const d1 = new Date("2021/1/13 12:00:00");
|
|
90
|
+
const d2 = new Date("2022/1/13 12:00:00");
|
|
91
|
+
const d3 = new Date("2022/1/13 12:10:01");
|
|
92
|
+
const d4 = new Date("2023/1/12 12:00:00");
|
|
93
|
+
expect(d3.substract(d1).totalYears > 1).toBeTruthy();
|
|
94
|
+
expect(d4.substract(d1).totalYears < 2).toBeTruthy();
|
|
95
|
+
expect(d2.substract(d1).totalMinutes > 10).toBeTruthy();
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
test(
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
test("Tests for parse", () => {
|
|
99
|
+
const d1 = DateUtils.parse("2014-01-01T13:13:34.441Z")?.toJSON();
|
|
100
|
+
expect(d1).toBe("2014-01-01T13:13:34.441Z");
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const d2 = DateUtils.parse("2024-03-01T11:41");
|
|
103
|
+
expect(d2?.getDate()).toBe(1);
|
|
104
|
+
expect(d2?.getHours()).toBe(11);
|
|
105
|
+
expect(d2?.getSeconds()).toBe(0);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
test(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
test("Tests for sameDay", () => {
|
|
109
|
+
expect(
|
|
110
|
+
DateUtils.sameDay("2022/9/11 22:03", new Date(2022, 8, 11, 10, 3))
|
|
111
|
+
).toBeTruthy();
|
|
112
|
+
expect(
|
|
113
|
+
DateUtils.sameDay("2022/9/11 22:03", new Date(2022, 9, 11, 10, 3))
|
|
114
|
+
).toBeFalsy();
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
test(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
test("Tests for sameMonth", () => {
|
|
118
|
+
expect(
|
|
119
|
+
DateUtils.sameMonth("2022-09-11 22:03", new Date(2022, 8, 10, 10, 3))
|
|
120
|
+
).toBeTruthy();
|
|
121
|
+
expect(
|
|
122
|
+
DateUtils.sameMonth("2022/9/11 22:03", "2022/8/31 23:59:59")
|
|
123
|
+
).toBeFalsy();
|
|
124
124
|
});
|