@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
@@ -6,7 +6,8 @@
6
6
  name: Node.js Package
7
7
 
8
8
  # Event to trigger the action
9
- on: [push]
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: '20.x'
32
- registry-url: 'https://registry.npmjs.org'
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 }}
@@ -1,150 +1,150 @@
1
- import { ArrayUtils } from '../src/ArrayUtils';
1
+ import { ArrayUtils } from "../src/ArrayUtils";
2
2
 
3
- test('Tests for simple type toUnique', () => {
4
- const result = [1, 1, 3, 5, 5].toUnique();
5
- expect(result).toStrictEqual([1, 3, 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('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);
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('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']);
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('Tests for sum numbers', () => {
25
- const items = [12, 8, 22];
26
- expect(items.sum()).toBe(42);
24
+ test("Tests for sum numbers", () => {
25
+ const items = [12, 8, 22];
26
+ expect(items.sum()).toBe(42);
27
27
  });
28
28
 
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);
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('Tests for max / min numbers', () => {
38
- const items = [12, 8, 22];
39
- expect(items.max()).toBe(22);
40
- expect(items.min()).toBe(8);
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('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);
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('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();
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('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);
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('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);
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('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']);
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('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
- ]);
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
  });
@@ -1,33 +1,33 @@
1
- import { EColor } from '../src/types/EColor';
2
- import { ColorUtils } from '../src/ColorUtils';
1
+ import { EColor } from "../src/types/EColor";
2
+ import { ColorUtils } from "../src/ColorUtils";
3
3
 
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)');
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('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)');
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
- // 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');
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('Tests for getColors', () => {
24
- const colors = ColorUtils.getColors(undefined, 128);
25
- expect(colors.length).toBe(8);
23
+ test("Tests for getColors", () => {
24
+ const colors = ColorUtils.getColors(undefined, 128);
25
+ expect(colors.length).toBe(8);
26
26
  });
27
27
 
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();
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 '../src/types/ContentDisposition';
1
+ import { ContentDisposition } from "../src/types/ContentDisposition";
2
2
 
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
- );
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
- const cd2 = ContentDisposition.parse(
9
- `attachment; filename="__PDF.pdf"; filename*="UTF-8''%E6%B5%8B%E8%AF%95PDF.pdf"`
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
- expect(cd1?.type).toBe(cd2?.type);
13
- expect(cd1?.filename).toBe(cd2?.filename);
14
- expect(cd1?.filename).toBe('测试PDF.pdf');
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('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
- );
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
  });