@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.
Files changed (106) hide show
  1. package/.github/workflows/main.yml +6 -5
  2. package/__tests__/ArrayUtils.ts +126 -126
  3. package/__tests__/ColorUtils.ts +24 -24
  4. package/__tests__/ContentDisposition.ts +18 -18
  5. package/__tests__/DataTypes.ts +222 -204
  6. package/__tests__/DateUtils.ts +82 -82
  7. package/__tests__/DomUtils.ts +352 -352
  8. package/__tests__/EHistory.ts +62 -62
  9. package/__tests__/ExtendUtils.ts +40 -40
  10. package/__tests__/Keyboard.ts +14 -14
  11. package/__tests__/NumberUtils.ts +37 -39
  12. package/__tests__/StorageUtils.ts +27 -27
  13. package/__tests__/Utils.ts +361 -363
  14. package/__tests__/tsconfig.json +15 -15
  15. package/lib/cjs/ActionResult.d.ts +1 -1
  16. package/lib/cjs/ActionResult.js +3 -3
  17. package/lib/cjs/ArrayUtils.d.ts +1 -1
  18. package/lib/cjs/ArrayUtils.js +4 -4
  19. package/lib/cjs/ColorUtils.d.ts +1 -1
  20. package/lib/cjs/ColorUtils.js +2 -2
  21. package/lib/cjs/DataTypes.d.ts +6 -6
  22. package/lib/cjs/DataTypes.js +50 -51
  23. package/lib/cjs/DateUtils.d.ts +1 -1
  24. package/lib/cjs/DateUtils.js +27 -28
  25. package/lib/cjs/DomUtils.d.ts +3 -3
  26. package/lib/cjs/DomUtils.js +64 -73
  27. package/lib/cjs/ExtendUtils.d.ts +1 -1
  28. package/lib/cjs/ExtendUtils.js +6 -6
  29. package/lib/cjs/IActionResult.d.ts +1 -1
  30. package/lib/cjs/NumberUtils.d.ts +1 -1
  31. package/lib/cjs/NumberUtils.js +9 -9
  32. package/lib/cjs/StorageUtils.js +2 -2
  33. package/lib/cjs/Utils.d.ts +4 -4
  34. package/lib/cjs/Utils.js +58 -62
  35. package/lib/cjs/index.d.ts +22 -22
  36. package/lib/cjs/storage/WindowStorage.d.ts +1 -1
  37. package/lib/cjs/types/ContentDisposition.d.ts +2 -2
  38. package/lib/cjs/types/ContentDisposition.js +11 -13
  39. package/lib/cjs/types/EColor.js +5 -7
  40. package/lib/cjs/types/EHistory.d.ts +3 -3
  41. package/lib/cjs/types/EHistory.js +4 -4
  42. package/lib/cjs/types/ErrorData.d.ts +1 -1
  43. package/lib/cjs/types/EventClass.js +1 -1
  44. package/lib/mjs/ActionResult.d.ts +1 -1
  45. package/lib/mjs/ActionResult.js +3 -3
  46. package/lib/mjs/ArrayUtils.d.ts +1 -1
  47. package/lib/mjs/ArrayUtils.js +5 -5
  48. package/lib/mjs/ColorUtils.d.ts +1 -1
  49. package/lib/mjs/ColorUtils.js +3 -3
  50. package/lib/mjs/DataTypes.d.ts +6 -6
  51. package/lib/mjs/DataTypes.js +50 -51
  52. package/lib/mjs/DateUtils.d.ts +1 -1
  53. package/lib/mjs/DateUtils.js +27 -28
  54. package/lib/mjs/DomUtils.d.ts +3 -3
  55. package/lib/mjs/DomUtils.js +67 -76
  56. package/lib/mjs/ExtendUtils.d.ts +1 -1
  57. package/lib/mjs/ExtendUtils.js +6 -6
  58. package/lib/mjs/IActionResult.d.ts +1 -1
  59. package/lib/mjs/NumberUtils.d.ts +1 -1
  60. package/lib/mjs/NumberUtils.js +9 -9
  61. package/lib/mjs/StorageUtils.js +4 -4
  62. package/lib/mjs/Utils.d.ts +4 -4
  63. package/lib/mjs/Utils.js +61 -65
  64. package/lib/mjs/index.d.ts +22 -22
  65. package/lib/mjs/index.js +22 -22
  66. package/lib/mjs/storage/WindowStorage.d.ts +1 -1
  67. package/lib/mjs/storage/WindowStorage.js +2 -2
  68. package/lib/mjs/types/ContentDisposition.d.ts +2 -2
  69. package/lib/mjs/types/ContentDisposition.js +12 -14
  70. package/lib/mjs/types/EColor.js +5 -7
  71. package/lib/mjs/types/EHistory.d.ts +3 -3
  72. package/lib/mjs/types/EHistory.js +5 -5
  73. package/lib/mjs/types/ErrorData.d.ts +1 -1
  74. package/lib/mjs/types/EventClass.js +1 -1
  75. package/package.json +61 -63
  76. package/src/ActionResult.ts +23 -23
  77. package/src/ArrayUtils.ts +164 -172
  78. package/src/ColorUtils.ts +80 -82
  79. package/src/DataTypes.ts +745 -754
  80. package/src/DateUtils.ts +266 -268
  81. package/src/DomUtils.ts +806 -831
  82. package/src/ExtendUtils.ts +191 -191
  83. package/src/IActionResult.ts +42 -42
  84. package/src/Keyboard.ts +258 -258
  85. package/src/NumberUtils.ts +135 -135
  86. package/src/StorageUtils.ts +117 -117
  87. package/src/Utils.ts +908 -930
  88. package/src/index.ts +22 -22
  89. package/src/node/Storage.ts +53 -53
  90. package/src/storage/IStorage.ts +62 -62
  91. package/src/storage/WindowStorage.ts +140 -140
  92. package/src/types/ContentDisposition.ts +59 -63
  93. package/src/types/DataError.ts +15 -15
  94. package/src/types/DelayedExecutorType.ts +15 -15
  95. package/src/types/EColor.ts +241 -248
  96. package/src/types/EHistory.ts +151 -151
  97. package/src/types/ErrorData.ts +11 -11
  98. package/src/types/EventClass.ts +220 -220
  99. package/src/types/FormData.ts +25 -25
  100. package/src/types/ParsedPath.ts +5 -5
  101. package/tsconfig.cjs.json +16 -16
  102. package/tsconfig.json +16 -16
  103. package/.eslintignore +0 -3
  104. package/.eslintrc.json +0 -29
  105. package/.prettierignore +0 -5
  106. package/.prettierrc +0 -6
@@ -1,420 +1,418 @@
1
- import { Utils } from '../src/Utils';
2
-
3
- test('Tests for addBlankItem', () => {
4
- const options = [
5
- { id: 1, name: 'a' },
6
- { id: 2, name: 'b' }
7
- ];
8
- Utils.addBlankItem(options, 'id', 'name');
9
- expect(options.length).toBe(3);
10
- expect(options[0].id).toBe('');
11
- expect(options[0].name).toBe('---');
12
- Utils.addBlankItem(options, 'id', 'name');
13
- expect(options.length).toBe(3);
14
- });
15
-
16
- test('Tests for addUrlParam', () => {
17
- const url = 'https://www.etsoo.com';
18
- const result = url.addUrlParam('a', 'b');
19
- expect(result).toBe('https://www.etsoo.com/?a=b');
20
- });
21
-
22
- describe('Tests for addUrlParams', () => {
23
- const url = 'https://www.etsoo.com';
24
- const data = {
25
- a: 'a',
26
- b: false,
27
- c: 123,
28
- d: new Date(Date.UTC(2022, 0, 28, 10)),
29
- e: [1, 2],
30
- f: ['a', 'b'],
31
- g: null
32
- };
33
- const result1 = url.addUrlParams(data);
34
-
35
- test('addUrlParams', () => {
36
- expect(result1).toBe(
37
- 'https://www.etsoo.com/?a=a&b=false&c=123&d=2022-01-28T10%3A00%3A00.000Z&e=1&e=2&f=a&f=b&g='
38
- );
39
- });
40
-
41
- const result2 = url.addUrlParams(data, true);
42
-
43
- test('addUrlParams with array format', () => {
44
- expect(result2).toBe(
45
- 'https://www.etsoo.com/?a=a&b=false&c=123&d=2022-01-28T10%3A00%3A00.000Z&e=1%2C2&f=a%2Cb&g='
46
- );
47
- });
48
-
49
- const result22 = '/'.addUrlParams(data);
50
- test('addUrlParams with relative path', () => {
51
- expect(result22).toBe(
52
- '/?a=a&b=false&c=123&d=2022-01-28T10%3A00%3A00.000Z&e=1&e=2&f=a&f=b&g='
53
- );
54
- });
55
-
56
- global.URL = undefined as any;
57
-
58
- const result3 = url.addUrlParams(data);
59
-
60
- test('addUrlParams with traditional way', () => {
61
- expect(result3).toBe(result1);
62
- });
63
-
64
- const result4 = url.addUrlParams(data, true);
65
-
66
- test('addUrlParams with traditional way and array format', () => {
67
- expect(result4).toBe(result2);
68
- });
69
- });
70
-
71
- test('Tests for containChinese', () => {
72
- expect('123 abC'.containChinese()).toBeFalsy();
73
- expect('亿速思维'.containChinese()).toBeTruthy();
74
- expect('亿速Etsoo'.containChinese()).toBeTruthy();
75
- expect('김 민수'.containKorean()).toBeTruthy();
76
- expect('ぁ-ん'.containJapanese()).toBeTruthy();
77
- });
78
-
79
- test('Tests for correctTypes', () => {
80
- const input = {
81
- id: '1',
82
- ignore: '2',
83
- price: '6.0',
84
- amount: '',
85
- date: '2022/01/28',
86
- enabled: 'true',
87
- ids: ['1', '2']
88
- };
89
- Utils.correctTypes(input, {
90
- id: 'number',
91
- price: 'number',
92
- amount: 'number',
93
- date: 'date',
94
- enabled: 'boolean',
95
- ids: 'number[]'
96
- });
97
- expect(typeof input.id).toBe('number');
98
- expect(typeof input.price).toBe('number');
99
- expect(input.amount).toBeUndefined();
100
- expect((input.date as any) instanceof Date ? true : false).toBeTruthy();
101
- expect(input.enabled).toBeTruthy();
102
- expect(input.ids).toStrictEqual([1, 2]);
103
- });
104
-
105
- test('Tests for getDataChanges', () => {
106
- const input = {
107
- id: 1,
108
- name: 'Name',
109
- gender: 'F',
110
- brand: '',
111
- price: '6.0',
112
- amount: '',
113
- enabled: true,
114
- value: undefined,
115
- date: new Date('2023/03/18'),
116
- ids: [1, 2],
117
- data: { d1: 1, d2: false, d3: 1.2, d4: 'Hello' }
118
- };
119
- const initData = {
120
- id: 1,
121
- name: 'Name',
122
- gender: 'M',
123
- brand: 'ETSOO',
124
- price: 6,
125
- amount: 0,
126
- date: '2023/03/18',
127
- enabled: true,
128
- ids: [1, 2],
129
- data: { d1: 1, d3: 1.2, d4: 'Hello', d2: false }
130
- };
131
- const fields = Utils.getDataChanges(input, initData);
132
- expect(fields).toStrictEqual(['gender', 'brand', 'amount']);
133
- expect(input.price).toBeUndefined();
134
- expect(input.amount).toBeUndefined();
135
- });
136
-
137
- test('Tests for object array getDataChanges', () => {
138
- const input = {
139
- id: 1,
140
- ids: [1, 2],
141
- items: [
142
- { id: 1, label: 'a' },
143
- { id: 2, label: 'b' }
144
- ]
145
- };
146
- const initData = {
147
- id: 1,
148
- ids: [1],
149
- items: [
150
- { id: 1, label: 'a' },
151
- { id: 2, label: 'b' }
152
- ]
153
- };
154
- const fields = Utils.getDataChanges(input, initData);
155
- expect(fields).toStrictEqual(['ids']);
156
- expect(input.items).toBeUndefined();
157
- });
158
-
159
- test('Tests for exclude', () => {
160
- const options = [
161
- { id1: 1, name: 'a' },
162
- { id1: 2, name: 'b' }
163
- ];
164
- const result = Utils.exclude(options, 'id1', 1);
165
- expect(result.length).toBe(1);
166
- expect(result[0].id1).toBe(2);
167
- });
168
-
169
- test('Tests for formatInitial', () => {
170
- expect(Utils.formatInitial('HelloWorld')).toBe('helloWorld');
171
- expect('HelloWorld'.formatInitial(false)).toBe('helloWorld');
172
- expect('hello'.formatInitial(true)).toBe('Hello');
173
- });
174
-
175
- test('Tests for formatString', () => {
176
- const template = '{0} is first item, {1} is second item, {0} repeat';
177
- const result = 'aa is first item, bb is second item, aa repeat';
178
- expect(Utils.formatString(template, 'aa', 'bb')).toBe(result);
179
- expect(template.format('aa', 'bb')).toBe(result);
180
- });
181
-
182
- test('Tests for hideData', () => {
183
- expect('xz@etsoo.com'.hideEmail()).toBe('x***@etsoo.com');
184
- expect('info@etsoo.com'.hideEmail()).toBe('in***@etsoo.com');
185
- expect('info@etsoo.com'.hideData('@')).toBe('in***@etsoo.com');
186
- expect('12345678'.hideData()).toBe('123***678');
187
- });
188
-
189
- test('Tests for isDigits', () => {
190
- expect(Utils.isDigits('1')).toBeTruthy();
191
- expect(Utils.isDigits('12', 3)).toBeFalsy();
192
- expect(Utils.isDigits('123', 3)).toBeTruthy();
193
- });
194
-
195
- test('Tests for isEmail', () => {
196
- expect(Utils.isEmail('abc')).toBeFalsy();
197
- expect(Utils.isEmail('a@')).toBeFalsy();
198
- expect(Utils.isEmail('xz@etsoo.com')).toBeTruthy();
199
- });
200
-
201
- test('Tests for joinItems', () => {
202
- expect(Utils.joinItems(['a', undefined, ' b', '', 'c '], ',')).toBe(
203
- 'a,b,c'
1
+ import { Utils } from "../src/Utils";
2
+
3
+ test("Tests for addBlankItem", () => {
4
+ const options = [
5
+ { id: 1, name: "a" },
6
+ { id: 2, name: "b" }
7
+ ];
8
+ Utils.addBlankItem(options, "id", "name");
9
+ expect(options.length).toBe(3);
10
+ expect(options[0].id).toBe("");
11
+ expect(options[0].name).toBe("---");
12
+ Utils.addBlankItem(options, "id", "name");
13
+ expect(options.length).toBe(3);
14
+ });
15
+
16
+ test("Tests for addUrlParam", () => {
17
+ const url = "https://www.etsoo.com";
18
+ const result = url.addUrlParam("a", "b");
19
+ expect(result).toBe("https://www.etsoo.com/?a=b");
20
+ });
21
+
22
+ describe("Tests for addUrlParams", () => {
23
+ const url = "https://www.etsoo.com";
24
+ const data = {
25
+ a: "a",
26
+ b: false,
27
+ c: 123,
28
+ d: new Date(Date.UTC(2022, 0, 28, 10)),
29
+ e: [1, 2],
30
+ f: ["a", "b"],
31
+ g: null
32
+ };
33
+ const result1 = url.addUrlParams(data);
34
+
35
+ test("addUrlParams", () => {
36
+ expect(result1).toBe(
37
+ "https://www.etsoo.com/?a=a&b=false&c=123&d=2022-01-28T10%3A00%3A00.000Z&e=1&e=2&f=a&f=b&g="
204
38
  );
205
- });
206
-
207
- test('Tests for newGUID', () => {
208
- // Arrange
209
- const id1 = Utils.newGUID();
210
- const id2 = Utils.newGUID();
39
+ });
211
40
 
212
- // Assert
213
- expect(id1).not.toEqual(id2);
214
- expect(id1.length).toBe(id2.length);
215
- });
41
+ const result2 = url.addUrlParams(data, true);
216
42
 
217
- test('Tests for numberToChars and charsToNumber', () => {
218
- const num = 1638777042242;
219
- const chars = Utils.numberToChars(num);
220
- expect(chars).toEqual('QmpkdVgv');
221
- expect(Utils.charsToNumber(chars)).toEqual(num);
222
- });
43
+ test("addUrlParams with array format", () => {
44
+ expect(result2).toBe(
45
+ "https://www.etsoo.com/?a=a&b=false&c=123&d=2022-01-28T10%3A00%3A00.000Z&e=1%2C2&f=a%2Cb&g="
46
+ );
47
+ });
223
48
 
224
- test('Tests for removeNonLetters', () => {
225
- const input = '1234-5678@abc.';
226
- const result = '12345678abc';
227
- expect(Utils.removeNonLetters(input)).toBe(result);
228
- expect(input.removeNonLetters()).toBe(result);
49
+ const result22 = "/".addUrlParams(data);
50
+ test("addUrlParams with relative path", () => {
51
+ expect(result22).toBe(
52
+ "/?a=a&b=false&c=123&d=2022-01-28T10%3A00%3A00.000Z&e=1&e=2&f=a&f=b&g="
53
+ );
54
+ });
55
+
56
+ global.URL = undefined as any;
57
+
58
+ const result3 = url.addUrlParams(data);
59
+
60
+ test("addUrlParams with traditional way", () => {
61
+ expect(result3).toBe(result1);
62
+ });
63
+
64
+ const result4 = url.addUrlParams(data, true);
65
+
66
+ test("addUrlParams with traditional way and array format", () => {
67
+ expect(result4).toBe(result2);
68
+ });
69
+ });
70
+
71
+ test("Tests for containChinese", () => {
72
+ expect("123 abC".containChinese()).toBeFalsy();
73
+ expect("亿速思维".containChinese()).toBeTruthy();
74
+ expect("亿速Etsoo".containChinese()).toBeTruthy();
75
+ expect("김 민수".containKorean()).toBeTruthy();
76
+ expect("ぁ-ん".containJapanese()).toBeTruthy();
77
+ });
78
+
79
+ test("Tests for correctTypes", () => {
80
+ const input = {
81
+ id: "1",
82
+ ignore: "2",
83
+ price: "6.0",
84
+ amount: "",
85
+ date: "2022/01/28",
86
+ enabled: "true",
87
+ ids: ["1", "2"]
88
+ };
89
+ Utils.correctTypes(input, {
90
+ id: "number",
91
+ price: "number",
92
+ amount: "number",
93
+ date: "date",
94
+ enabled: "boolean",
95
+ ids: "number[]"
96
+ });
97
+ expect(typeof input.id).toBe("number");
98
+ expect(typeof input.price).toBe("number");
99
+ expect(input.amount).toBeUndefined();
100
+ expect((input.date as any) instanceof Date ? true : false).toBeTruthy();
101
+ expect(input.enabled).toBeTruthy();
102
+ expect(input.ids).toStrictEqual([1, 2]);
103
+ });
104
+
105
+ test("Tests for getDataChanges", () => {
106
+ const input = {
107
+ id: 1,
108
+ name: "Name",
109
+ gender: "F",
110
+ brand: "",
111
+ price: "6.0",
112
+ amount: "",
113
+ enabled: true,
114
+ value: undefined,
115
+ date: new Date("2023/03/18"),
116
+ ids: [1, 2],
117
+ data: { d1: 1, d2: false, d3: 1.2, d4: "Hello" }
118
+ };
119
+ const initData = {
120
+ id: 1,
121
+ name: "Name",
122
+ gender: "M",
123
+ brand: "ETSOO",
124
+ price: 6,
125
+ amount: 0,
126
+ date: "2023/03/18",
127
+ enabled: true,
128
+ ids: [1, 2],
129
+ data: { d1: 1, d3: 1.2, d4: "Hello", d2: false }
130
+ };
131
+ const fields = Utils.getDataChanges(input, initData);
132
+ expect(fields).toStrictEqual(["gender", "brand", "amount"]);
133
+ expect(input.price).toBeUndefined();
134
+ expect(input.amount).toBeUndefined();
135
+ });
136
+
137
+ test("Tests for object array getDataChanges", () => {
138
+ const input = {
139
+ id: 1,
140
+ ids: [1, 2],
141
+ items: [
142
+ { id: 1, label: "a" },
143
+ { id: 2, label: "b" }
144
+ ]
145
+ };
146
+ const initData = {
147
+ id: 1,
148
+ ids: [1],
149
+ items: [
150
+ { id: 1, label: "a" },
151
+ { id: 2, label: "b" }
152
+ ]
153
+ };
154
+ const fields = Utils.getDataChanges(input, initData);
155
+ expect(fields).toStrictEqual(["ids"]);
156
+ expect(input.items).toBeUndefined();
157
+ });
158
+
159
+ test("Tests for exclude", () => {
160
+ const options = [
161
+ { id1: 1, name: "a" },
162
+ { id1: 2, name: "b" }
163
+ ];
164
+ const result = Utils.exclude(options, "id1", 1);
165
+ expect(result.length).toBe(1);
166
+ expect(result[0].id1).toBe(2);
167
+ });
168
+
169
+ test("Tests for formatInitial", () => {
170
+ expect(Utils.formatInitial("HelloWorld")).toBe("helloWorld");
171
+ expect("HelloWorld".formatInitial(false)).toBe("helloWorld");
172
+ expect("hello".formatInitial(true)).toBe("Hello");
173
+ });
174
+
175
+ test("Tests for formatString", () => {
176
+ const template = "{0} is first item, {1} is second item, {0} repeat";
177
+ const result = "aa is first item, bb is second item, aa repeat";
178
+ expect(Utils.formatString(template, "aa", "bb")).toBe(result);
179
+ expect(template.format("aa", "bb")).toBe(result);
180
+ });
181
+
182
+ test("Tests for hideData", () => {
183
+ expect("xz@etsoo.com".hideEmail()).toBe("x***@etsoo.com");
184
+ expect("info@etsoo.com".hideEmail()).toBe("in***@etsoo.com");
185
+ expect("info@etsoo.com".hideData("@")).toBe("in***@etsoo.com");
186
+ expect("12345678".hideData()).toBe("123***678");
187
+ });
188
+
189
+ test("Tests for isDigits", () => {
190
+ expect(Utils.isDigits("1")).toBeTruthy();
191
+ expect(Utils.isDigits("12", 3)).toBeFalsy();
192
+ expect(Utils.isDigits("123", 3)).toBeTruthy();
193
+ });
194
+
195
+ test("Tests for isEmail", () => {
196
+ expect(Utils.isEmail("abc")).toBeFalsy();
197
+ expect(Utils.isEmail("a@")).toBeFalsy();
198
+ expect(Utils.isEmail("xz@etsoo.com")).toBeTruthy();
199
+ });
200
+
201
+ test("Tests for joinItems", () => {
202
+ expect(Utils.joinItems(["a", undefined, " b", "", "c "], ",")).toBe("a,b,c");
203
+ });
204
+
205
+ test("Tests for newGUID", () => {
206
+ // Arrange
207
+ const id1 = Utils.newGUID();
208
+ const id2 = Utils.newGUID();
209
+
210
+ // Assert
211
+ expect(id1).not.toEqual(id2);
212
+ expect(id1.length).toBe(id2.length);
213
+ });
214
+
215
+ test("Tests for numberToChars and charsToNumber", () => {
216
+ const num = 1638777042242;
217
+ const chars = Utils.numberToChars(num);
218
+ expect(chars).toEqual("QmpkdVgv");
219
+ expect(Utils.charsToNumber(chars)).toEqual(num);
220
+ });
221
+
222
+ test("Tests for removeNonLetters", () => {
223
+ const input = "1234-5678@abc.";
224
+ const result = "12345678abc";
225
+ expect(Utils.removeNonLetters(input)).toBe(result);
226
+ expect(input.removeNonLetters()).toBe(result);
229
227
  });
230
228
 
231
- test('Tests for replaceNullOrEmpty', () => {
232
- expect(Utils.replaceNullOrEmpty('a', 's')).toBe('a');
233
- expect(Utils.replaceNullOrEmpty(null, 's')).toBe('s');
234
- expect(Utils.replaceNullOrEmpty(' ', 's')).toBe('s');
229
+ test("Tests for replaceNullOrEmpty", () => {
230
+ expect(Utils.replaceNullOrEmpty("a", "s")).toBe("a");
231
+ expect(Utils.replaceNullOrEmpty(null, "s")).toBe("s");
232
+ expect(Utils.replaceNullOrEmpty(" ", "s")).toBe("s");
235
233
  });
236
234
 
237
- test('Tests for objectEqual', () => {
238
- const obj1 = { a: 1, b: 'abc', c: true, d: null, f: [1, 2] };
239
- const obj2 = { a: '1', b: 'abc', c: true, f: [1, 2] };
240
- expect(Utils.objectEqual(obj1, obj2)).toBeFalsy();
241
- expect(Utils.objectEqual(obj1, obj2, [], 0)).toBeTruthy();
242
- expect(Utils.objectEqual(obj1, obj2, ['a'])).toBeTruthy();
243
- expect(Utils.objectEqual(obj1, obj2, ['a'], 2)).toBeFalsy();
235
+ test("Tests for objectEqual", () => {
236
+ const obj1 = { a: 1, b: "abc", c: true, d: null, f: [1, 2] };
237
+ const obj2 = { a: "1", b: "abc", c: true, f: [1, 2] };
238
+ expect(Utils.objectEqual(obj1, obj2)).toBeFalsy();
239
+ expect(Utils.objectEqual(obj1, obj2, [], 0)).toBeTruthy();
240
+ expect(Utils.objectEqual(obj1, obj2, ["a"])).toBeTruthy();
241
+ expect(Utils.objectEqual(obj1, obj2, ["a"], 2)).toBeFalsy();
244
242
  });
245
243
 
246
- test('Tests for parseJsonArray', () => {
247
- expect(Utils.parseJsonArray('[1, 3, "a"]', 0)).toBeUndefined();
248
- expect(Utils.parseJsonArray('[1, 3, "a"]')).not.toBeUndefined();
249
- expect(Utils.parseJsonArray('1, 3, 9')).not.toBeUndefined();
244
+ test("Tests for parseJsonArray", () => {
245
+ expect(Utils.parseJsonArray('[1, 3, "a"]', 0)).toBeUndefined();
246
+ expect(Utils.parseJsonArray('[1, 3, "a"]')).not.toBeUndefined();
247
+ expect(Utils.parseJsonArray("1, 3, 9")).not.toBeUndefined();
250
248
  });
251
249
 
252
- test('Tests for objectUpdated', () => {
253
- const objPrev = { a: 1, b: 'abc', c: true, d: null, f: [1, 2] };
254
- const objNew = { a: 2, b: 'abc', d: new Date(), f: [1, 2, 3], g: true };
255
- const fields = Utils.objectUpdated(objNew, objPrev, ['d']);
256
- expect(fields.sort()).toStrictEqual(['a', 'c', 'f', 'g']);
250
+ test("Tests for objectUpdated", () => {
251
+ const objPrev = { a: 1, b: "abc", c: true, d: null, f: [1, 2] };
252
+ const objNew = { a: 2, b: "abc", d: new Date(), f: [1, 2, 3], g: true };
253
+ const fields = Utils.objectUpdated(objNew, objPrev, ["d"]);
254
+ expect(fields.sort()).toStrictEqual(["a", "c", "f", "g"]);
257
255
  });
258
256
 
259
- test('Tests for parseString', () => {
260
- expect(Utils.parseString<string>('test')).toBe('test');
261
- expect(Utils.parseString('test', '')).toBe('test');
262
- expect(Utils.parseString('true', false)).toBe(true);
263
- expect(Utils.parseString('', false)).toBeFalsy();
264
- expect(Utils.parseString<boolean>('')).toBeUndefined();
265
- expect(Utils.parseString<number>(undefined)).toBeUndefined();
266
- expect(Utils.parseString('3.14', 0)).toBe(3.14);
267
- expect(Utils.parseString(null, 0)).toBe(0);
268
- expect(Utils.parseString('2021/4/13', new Date())).toStrictEqual(
269
- new Date('2021/4/13')
270
- );
257
+ test("Tests for parseString", () => {
258
+ expect(Utils.parseString<string>("test")).toBe("test");
259
+ expect(Utils.parseString("test", "")).toBe("test");
260
+ expect(Utils.parseString("true", false)).toBe(true);
261
+ expect(Utils.parseString("", false)).toBeFalsy();
262
+ expect(Utils.parseString<boolean>("")).toBeUndefined();
263
+ expect(Utils.parseString<number>(undefined)).toBeUndefined();
264
+ expect(Utils.parseString("3.14", 0)).toBe(3.14);
265
+ expect(Utils.parseString(null, 0)).toBe(0);
266
+ expect(Utils.parseString("2021/4/13", new Date())).toStrictEqual(
267
+ new Date("2021/4/13")
268
+ );
271
269
  });
272
270
 
273
- test('Test for setLabels', () => {
274
- // Arrange
275
- const source = { label: 'Hello' };
276
- const newLabel = 'world';
271
+ test("Test for setLabels", () => {
272
+ // Arrange
273
+ const source = { label: "Hello" };
274
+ const newLabel = "world";
277
275
 
278
- // Act
279
- Utils.setLabels(source, { label1: newLabel }, { label: 'label1' });
276
+ // Act
277
+ Utils.setLabels(source, { label1: newLabel }, { label: "label1" });
280
278
 
281
- // Assert
282
- expect(source.label).toBe(newLabel);
279
+ // Assert
280
+ expect(source.label).toBe(newLabel);
283
281
  });
284
282
 
285
- test('Test for snakeNameToWord', () => {
286
- expect(Utils.snakeNameToWord('snake_name')).toBe('Snake Name');
287
- expect(Utils.snakeNameToWord('snake_name', true)).toBe('Snake name');
283
+ test("Test for snakeNameToWord", () => {
284
+ expect(Utils.snakeNameToWord("snake_name")).toBe("Snake Name");
285
+ expect(Utils.snakeNameToWord("snake_name", true)).toBe("Snake name");
288
286
  });
289
287
 
290
- test('Tests for mergeClasses', () => {
291
- expect(Utils.mergeClasses('a', '', 'b ', undefined, 'c')).toBe('a b c');
288
+ test("Tests for mergeClasses", () => {
289
+ expect(Utils.mergeClasses("a", "", "b ", undefined, "c")).toBe("a b c");
292
290
  });
293
291
 
294
- test('Tests for getNestedValue', () => {
295
- const obj = { jsonData: { photoSize: [200, 100], supportResizing: true } };
296
- expect(Utils.getNestedValue(obj, 'jsonData.supportResizing')).toBeTruthy();
297
- expect(
298
- Array.isArray(Utils.getNestedValue(obj, 'jsonData.photoSize'))
299
- ).toBeTruthy();
300
- expect(Utils.getNestedValue(obj, 'jsonData.unknown')).toBeUndefined();
292
+ test("Tests for getNestedValue", () => {
293
+ const obj = { jsonData: { photoSize: [200, 100], supportResizing: true } };
294
+ expect(Utils.getNestedValue(obj, "jsonData.supportResizing")).toBeTruthy();
295
+ expect(
296
+ Array.isArray(Utils.getNestedValue(obj, "jsonData.photoSize"))
297
+ ).toBeTruthy();
298
+ expect(Utils.getNestedValue(obj, "jsonData.unknown")).toBeUndefined();
301
299
  });
302
300
 
303
- test('Tests for getResult', () => {
304
- // Arrange
305
- type test = ((visible: boolean) => number) | number;
306
- const input: test = (visible) => (visible ? 1 : 0);
307
- const inputNumber: test = 5;
301
+ test("Tests for getResult", () => {
302
+ // Arrange
303
+ type test = ((visible: boolean) => number) | number;
304
+ const input: test = (visible) => (visible ? 1 : 0);
305
+ const inputNumber: test = 5;
308
306
 
309
- // Act & assert
310
- const result = Utils.getResult(input, true);
311
- expect(result).toBe(1);
312
- expect(Utils.getResult(input, false)).toBe(0);
307
+ // Act & assert
308
+ const result = Utils.getResult(input, true);
309
+ expect(result).toBe(1);
310
+ expect(Utils.getResult(input, false)).toBe(0);
313
311
 
314
- const valueResult = Utils.getResult(inputNumber);
315
- expect(valueResult).toBe(5);
312
+ const valueResult = Utils.getResult(inputNumber);
313
+ expect(valueResult).toBe(5);
316
314
  });
317
315
 
318
- test('Tests for parsePath, file only', () => {
319
- const result = Utils.parsePath('a.jpg');
320
- expect(result.root).toBe('');
321
- expect(result.dir).toBe('');
322
- expect(result.base).toBe('a.jpg');
323
- expect(result.ext).toBe('.jpg');
324
- expect(result.name).toBe('a');
316
+ test("Tests for parsePath, file only", () => {
317
+ const result = Utils.parsePath("a.jpg");
318
+ expect(result.root).toBe("");
319
+ expect(result.dir).toBe("");
320
+ expect(result.base).toBe("a.jpg");
321
+ expect(result.ext).toBe(".jpg");
322
+ expect(result.name).toBe("a");
325
323
  });
326
324
 
327
- test('Tests for parsePath, root file only', () => {
328
- const result = Utils.parsePath('/a.JPG');
329
- expect(result.root).toBe('/');
330
- expect(result.dir).toBe('/');
331
- expect(result.base).toBe('a.JPG');
332
- expect(result.ext).toBe('.JPG');
333
- expect(result.name).toBe('a');
325
+ test("Tests for parsePath, root file only", () => {
326
+ const result = Utils.parsePath("/a.JPG");
327
+ expect(result.root).toBe("/");
328
+ expect(result.dir).toBe("/");
329
+ expect(result.base).toBe("a.JPG");
330
+ expect(result.ext).toBe(".JPG");
331
+ expect(result.name).toBe("a");
334
332
  });
335
333
 
336
- test('Tests for parsePath, Linux path', () => {
337
- const result = Utils.parsePath('/home/user/dir/file.txt');
338
- expect(result.root).toBe('/');
339
- expect(result.dir).toBe('/home/user/dir');
340
- expect(result.base).toBe('file.txt');
341
- expect(result.ext).toBe('.txt');
342
- expect(result.name).toBe('file');
334
+ test("Tests for parsePath, Linux path", () => {
335
+ const result = Utils.parsePath("/home/user/dir/file.txt");
336
+ expect(result.root).toBe("/");
337
+ expect(result.dir).toBe("/home/user/dir");
338
+ expect(result.base).toBe("file.txt");
339
+ expect(result.ext).toBe(".txt");
340
+ expect(result.name).toBe("file");
343
341
  });
344
342
 
345
- test('Tests for parsePath, Windows path', () => {
346
- const result = Utils.parsePath('C:\\path\\dir\\file.txt');
347
- expect(result.root).toBe('C:\\');
348
- expect(result.dir).toBe('C:\\path\\dir');
349
- expect(result.base).toBe('file.txt');
350
- expect(result.ext).toBe('.txt');
351
- expect(result.name).toBe('file');
343
+ test("Tests for parsePath, Windows path", () => {
344
+ const result = Utils.parsePath("C:\\path\\dir\\file.txt");
345
+ expect(result.root).toBe("C:\\");
346
+ expect(result.dir).toBe("C:\\path\\dir");
347
+ expect(result.base).toBe("file.txt");
348
+ expect(result.ext).toBe(".txt");
349
+ expect(result.name).toBe("file");
352
350
  });
353
351
 
354
- test('Tests for removeEmptyValues', () => {
355
- const obj = { a: 1, b: '', c: null, d: undefined, e: 'e' };
356
- Utils.removeEmptyValues(obj);
357
- expect(obj).toEqual({ a: 1, e: 'e' });
352
+ test("Tests for removeEmptyValues", () => {
353
+ const obj = { a: 1, b: "", c: null, d: undefined, e: "e" };
354
+ Utils.removeEmptyValues(obj);
355
+ expect(obj).toEqual({ a: 1, e: "e" });
358
356
  });
359
357
 
360
- test('Tests for setNestedValue', () => {
361
- const obj = { jsonData: { photoSize: [200, 100], supportResizing: true } };
358
+ test("Tests for setNestedValue", () => {
359
+ const obj = { jsonData: { photoSize: [200, 100], supportResizing: true } };
362
360
 
363
- Utils.setNestedValue(obj, 'jsonData.supportResizing', false);
364
- expect(obj.jsonData.supportResizing).toBeFalsy();
361
+ Utils.setNestedValue(obj, "jsonData.supportResizing", false);
362
+ expect(obj.jsonData.supportResizing).toBeFalsy();
365
363
 
366
- Utils.setNestedValue(obj, 'jsonData.newProperty.value', 125);
367
- expect(Reflect.get((obj.jsonData as any).newProperty, 'value')).toBe(125);
364
+ Utils.setNestedValue(obj, "jsonData.newProperty.value", 125);
365
+ expect(Reflect.get((obj.jsonData as any).newProperty, "value")).toBe(125);
368
366
  });
369
367
 
370
- test('Tests for setNestedValue removal', () => {
371
- const obj = { jsonData: { photoSize: [200, 100], supportResizing: true } };
368
+ test("Tests for setNestedValue removal", () => {
369
+ const obj = { jsonData: { photoSize: [200, 100], supportResizing: true } };
372
370
 
373
- Utils.setNestedValue(obj, 'jsonData.photoSize', undefined);
374
- expect(obj.jsonData.photoSize).toBeUndefined();
371
+ Utils.setNestedValue(obj, "jsonData.photoSize", undefined);
372
+ expect(obj.jsonData.photoSize).toBeUndefined();
375
373
 
376
- Utils.setNestedValue(obj, 'jsonData.supportResizing', undefined);
377
- expect(obj.jsonData.supportResizing).toBeUndefined();
374
+ Utils.setNestedValue(obj, "jsonData.supportResizing", undefined);
375
+ expect(obj.jsonData.supportResizing).toBeUndefined();
378
376
  });
379
377
 
380
- test('Tests for sortByFavor', () => {
381
- const items = [1, 2, 3, 4, 5, 6, 7];
382
- expect(Utils.sortByFavor(items, [5, 1, 3])).toStrictEqual([
383
- 5, 1, 3, 2, 4, 6, 7
384
- ]);
378
+ test("Tests for sortByFavor", () => {
379
+ const items = [1, 2, 3, 4, 5, 6, 7];
380
+ expect(Utils.sortByFavor(items, [5, 1, 3])).toStrictEqual([
381
+ 5, 1, 3, 2, 4, 6, 7
382
+ ]);
385
383
  });
386
384
 
387
- test('Tests for sortByFieldFavor', () => {
388
- const options = [
389
- { id: 'a', name: 'a1' },
390
- { id: 'b', name: 'b2' },
391
- { id: 'c', name: 'c3' },
392
- { id: 'd', name: 'd4' },
393
- { id: 'e', name: 'e5' },
394
- { id: 'f', name: 'f6' }
395
- ];
396
- expect(
397
- Utils.sortByFieldFavor(options, 'id', ['e', 'a', 'c']).map(
398
- (option) => option.name
399
- )
400
- ).toStrictEqual(['e5', 'a1', 'c3', 'b2', 'd4', 'f6']);
385
+ test("Tests for sortByFieldFavor", () => {
386
+ const options = [
387
+ { id: "a", name: "a1" },
388
+ { id: "b", name: "b2" },
389
+ { id: "c", name: "c3" },
390
+ { id: "d", name: "d4" },
391
+ { id: "e", name: "e5" },
392
+ { id: "f", name: "f6" }
393
+ ];
394
+ expect(
395
+ Utils.sortByFieldFavor(options, "id", ["e", "a", "c"]).map(
396
+ (option) => option.name
397
+ )
398
+ ).toStrictEqual(["e5", "a1", "c3", "b2", "d4", "f6"]);
401
399
  });
402
400
 
403
- test('Tests for trim', () => {
404
- expect(Utils.trim('//a/', '/')).toBe('a');
405
- expect(Utils.trim('/*/a/', ...['/', '*'])).toBe('a');
406
- expect(Utils.trim('abc', ...['/', '*'])).toBe('abc');
401
+ test("Tests for trim", () => {
402
+ expect(Utils.trim("//a/", "/")).toBe("a");
403
+ expect(Utils.trim("/*/a/", ...["/", "*"])).toBe("a");
404
+ expect(Utils.trim("abc", ...["/", "*"])).toBe("abc");
407
405
  });
408
406
 
409
- test('Tests for trimStart', () => {
410
- expect(Utils.trimStart('//a/', '/')).toBe('a/');
411
- expect(Utils.trimStart('/*/a/', ...['/', '*'])).toBe('a/');
412
- expect(Utils.trimStart('abc', ...['/', '*'])).toBe('abc');
407
+ test("Tests for trimStart", () => {
408
+ expect(Utils.trimStart("//a/", "/")).toBe("a/");
409
+ expect(Utils.trimStart("/*/a/", ...["/", "*"])).toBe("a/");
410
+ expect(Utils.trimStart("abc", ...["/", "*"])).toBe("abc");
413
411
  });
414
412
 
415
- test('Tests for trimEnd', () => {
416
- expect(Utils.trimEnd('//a/', '/')).toBe('//a');
417
- expect(Utils.trimEnd('/*/a*/', ...['/', '*'])).toBe('/*/a');
418
- expect(Utils.trimEnd('abc', ...['/', '*'])).toBe('abc');
419
- expect(Utils.trimEnd('12.0.0.0', '.0')).toBe('12');
413
+ test("Tests for trimEnd", () => {
414
+ expect(Utils.trimEnd("//a/", "/")).toBe("//a");
415
+ expect(Utils.trimEnd("/*/a*/", ...["/", "*"])).toBe("/*/a");
416
+ expect(Utils.trimEnd("abc", ...["/", "*"])).toBe("abc");
417
+ expect(Utils.trimEnd("12.0.0.0", ".0")).toBe("12");
420
418
  });