@etsoo/shared 1.2.52 → 1.2.54

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 (93) hide show
  1. package/.github/workflows/main.yml +6 -5
  2. package/lib/cjs/ActionResult.d.ts +1 -1
  3. package/lib/cjs/ActionResult.js +3 -3
  4. package/lib/cjs/ArrayUtils.d.ts +1 -1
  5. package/lib/cjs/ArrayUtils.js +4 -4
  6. package/lib/cjs/ColorUtils.d.ts +1 -1
  7. package/lib/cjs/ColorUtils.js +2 -2
  8. package/lib/cjs/DataTypes.d.ts +6 -6
  9. package/lib/cjs/DataTypes.js +50 -51
  10. package/lib/cjs/DateUtils.d.ts +1 -1
  11. package/lib/cjs/DateUtils.js +27 -28
  12. package/lib/cjs/DomUtils.d.ts +3 -3
  13. package/lib/cjs/DomUtils.js +64 -73
  14. package/lib/cjs/ExtendUtils.d.ts +1 -1
  15. package/lib/cjs/ExtendUtils.js +6 -6
  16. package/lib/cjs/IActionResult.d.ts +1 -1
  17. package/lib/cjs/NumberUtils.d.ts +1 -1
  18. package/lib/cjs/NumberUtils.js +9 -9
  19. package/lib/cjs/StorageUtils.js +2 -2
  20. package/lib/cjs/Utils.d.ts +4 -4
  21. package/lib/cjs/Utils.js +58 -62
  22. package/lib/cjs/index.d.ts +22 -22
  23. package/lib/cjs/storage/WindowStorage.d.ts +1 -1
  24. package/lib/cjs/types/ContentDisposition.d.ts +2 -2
  25. package/lib/cjs/types/ContentDisposition.js +11 -13
  26. package/lib/cjs/types/EColor.js +5 -7
  27. package/lib/cjs/types/EHistory.d.ts +3 -3
  28. package/lib/cjs/types/EHistory.js +4 -4
  29. package/lib/cjs/types/ErrorData.d.ts +1 -1
  30. package/lib/cjs/types/EventClass.js +1 -1
  31. package/lib/mjs/ActionResult.d.ts +1 -1
  32. package/lib/mjs/ActionResult.js +3 -3
  33. package/lib/mjs/ArrayUtils.d.ts +1 -1
  34. package/lib/mjs/ArrayUtils.js +5 -5
  35. package/lib/mjs/ColorUtils.d.ts +1 -1
  36. package/lib/mjs/ColorUtils.js +3 -3
  37. package/lib/mjs/DataTypes.d.ts +6 -6
  38. package/lib/mjs/DataTypes.js +50 -51
  39. package/lib/mjs/DateUtils.d.ts +1 -1
  40. package/lib/mjs/DateUtils.js +27 -28
  41. package/lib/mjs/DomUtils.d.ts +3 -3
  42. package/lib/mjs/DomUtils.js +67 -76
  43. package/lib/mjs/ExtendUtils.d.ts +1 -1
  44. package/lib/mjs/ExtendUtils.js +6 -6
  45. package/lib/mjs/IActionResult.d.ts +1 -1
  46. package/lib/mjs/NumberUtils.d.ts +1 -1
  47. package/lib/mjs/NumberUtils.js +9 -9
  48. package/lib/mjs/StorageUtils.js +4 -4
  49. package/lib/mjs/Utils.d.ts +4 -4
  50. package/lib/mjs/Utils.js +61 -65
  51. package/lib/mjs/index.d.ts +22 -22
  52. package/lib/mjs/index.js +22 -22
  53. package/lib/mjs/storage/WindowStorage.d.ts +1 -1
  54. package/lib/mjs/storage/WindowStorage.js +2 -2
  55. package/lib/mjs/types/ContentDisposition.d.ts +2 -2
  56. package/lib/mjs/types/ContentDisposition.js +12 -14
  57. package/lib/mjs/types/EColor.js +5 -7
  58. package/lib/mjs/types/EHistory.d.ts +3 -3
  59. package/lib/mjs/types/EHistory.js +5 -5
  60. package/lib/mjs/types/ErrorData.d.ts +1 -1
  61. package/lib/mjs/types/EventClass.js +1 -1
  62. package/package.json +61 -63
  63. package/src/ActionResult.ts +23 -23
  64. package/src/ArrayUtils.ts +164 -172
  65. package/src/ColorUtils.ts +80 -82
  66. package/src/DataTypes.ts +745 -754
  67. package/src/DateUtils.ts +266 -268
  68. package/src/DomUtils.ts +806 -831
  69. package/src/ExtendUtils.ts +191 -191
  70. package/src/IActionResult.ts +42 -42
  71. package/src/Keyboard.ts +258 -258
  72. package/src/NumberUtils.ts +135 -135
  73. package/src/StorageUtils.ts +117 -117
  74. package/src/Utils.ts +908 -930
  75. package/src/index.ts +22 -22
  76. package/src/node/Storage.ts +53 -53
  77. package/src/storage/IStorage.ts +62 -62
  78. package/src/storage/WindowStorage.ts +140 -140
  79. package/src/types/ContentDisposition.ts +59 -63
  80. package/src/types/DataError.ts +15 -15
  81. package/src/types/DelayedExecutorType.ts +15 -15
  82. package/src/types/EColor.ts +241 -248
  83. package/src/types/EHistory.ts +151 -151
  84. package/src/types/ErrorData.ts +11 -11
  85. package/src/types/EventClass.ts +220 -220
  86. package/src/types/FormData.ts +25 -25
  87. package/src/types/ParsedPath.ts +5 -5
  88. package/tsconfig.cjs.json +16 -16
  89. package/tsconfig.json +16 -16
  90. package/.eslintignore +0 -3
  91. package/.eslintrc.json +0 -29
  92. package/.prettierignore +0 -5
  93. package/.prettierrc +0 -6
@@ -1,152 +1,152 @@
1
1
  declare global {
2
- interface Number {
3
- /**
4
- * To the exact precision number avoiding precision lost
5
- * @param precision Precision
6
- */
7
- toExact(precision?: number): number;
8
- }
2
+ interface Number {
3
+ /**
4
+ * To the exact precision number avoiding precision lost
5
+ * @param precision Precision
6
+ */
7
+ toExact(precision?: number): number;
8
+ }
9
9
  }
10
10
 
11
11
  Number.prototype.toExact = function (this: number, precision?: number) {
12
- if (precision == null || precision < 0) precision = 2;
12
+ if (precision == null || precision < 0) precision = 2;
13
13
 
14
- if (precision === 0) return Math.round(this);
14
+ if (precision === 0) return Math.round(this);
15
15
 
16
- const p = Math.pow(10, precision);
17
- return Math.round(this * p) / p;
16
+ const p = Math.pow(10, precision);
17
+ return Math.round(this * p) / p;
18
18
  };
19
19
 
20
20
  export namespace NumberUtils {
21
- /**
22
- * Format number
23
- * @param input Input
24
- * @param locale Locale
25
- * @param options Options
26
- * @returns Result
27
- */
28
- export function format(
29
- input: number | bigint,
30
- locale?: string | string[],
31
- options?: Intl.NumberFormatOptions
32
- ) {
33
- // Formatter
34
- const intl = new Intl.NumberFormat(locale, options);
35
- return intl.format(input);
21
+ /**
22
+ * Format number
23
+ * @param input Input
24
+ * @param locale Locale
25
+ * @param options Options
26
+ * @returns Result
27
+ */
28
+ export function format(
29
+ input: number | bigint,
30
+ locale?: string | string[],
31
+ options?: Intl.NumberFormatOptions
32
+ ) {
33
+ // Formatter
34
+ const intl = new Intl.NumberFormat(locale, options);
35
+ return intl.format(input);
36
+ }
37
+
38
+ /**
39
+ * Format money
40
+ * @param input Input
41
+ * @param currency Currency, like USD for US dollar
42
+ * @param locale Locale
43
+ * @param isInteger Is integer value
44
+ * @param options Options
45
+ * @returns Result
46
+ */
47
+ export function formatMoney(
48
+ input: number | bigint,
49
+ currency?: string,
50
+ locale?: string | string[],
51
+ isInteger: boolean = false,
52
+ options: Intl.NumberFormatOptions = {}
53
+ ) {
54
+ if (currency) {
55
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
56
+ options.style = "currency";
57
+ options.currency = currency;
58
+ options.currencyDisplay ??= "narrowSymbol";
36
59
  }
37
60
 
38
- /**
39
- * Format money
40
- * @param input Input
41
- * @param currency Currency, like USD for US dollar
42
- * @param locale Locale
43
- * @param isInteger Is integer value
44
- * @param options Options
45
- * @returns Result
46
- */
47
- export function formatMoney(
48
- input: number | bigint,
49
- currency?: string,
50
- locale?: string | string[],
51
- isInteger: boolean = false,
52
- options: Intl.NumberFormatOptions = {}
53
- ) {
54
- if (currency) {
55
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
56
- options.style = 'currency';
57
- options.currency = currency;
58
- options.currencyDisplay ??= 'narrowSymbol';
59
- }
60
-
61
- if (isInteger) {
62
- options.minimumFractionDigits ??= 0;
63
- options.maximumFractionDigits ??= 0;
64
- } else options.minimumFractionDigits ??= 2;
65
-
66
- return format(input, locale, options);
61
+ if (isInteger) {
62
+ options.minimumFractionDigits ??= 0;
63
+ options.maximumFractionDigits ??= 0;
64
+ } else options.minimumFractionDigits ??= 2;
65
+
66
+ return format(input, locale, options);
67
+ }
68
+
69
+ /**
70
+ * Format file size
71
+ * @param size File size
72
+ * @param fractionDigits Fraction digits
73
+ * @returns Result
74
+ */
75
+ export function formatFileSize(size: number, fractionDigits: number = 2) {
76
+ const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
77
+ return (
78
+ (size / Math.pow(1024, i)).toFixed(fractionDigits) +
79
+ " " +
80
+ ["B", "KB", "MB", "GB", "TB", "PB"][i]
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Get currency symbol or name from ISO code
86
+ * @param code ISO currency code, like USD / CNY
87
+ * @param display Display format
88
+ * @param locale Locale
89
+ * @returns Result
90
+ */
91
+ export function getCurrencySymbol(
92
+ code: string,
93
+ display: "symbol" | "narrowSymbol" | "name" = "narrowSymbol",
94
+ locale?: string
95
+ ): string | undefined {
96
+ const formatter = new Intl.NumberFormat(locale, {
97
+ style: "currency",
98
+ currency: code,
99
+ currencyDisplay: display
100
+ });
101
+
102
+ const parts = formatter.formatToParts();
103
+ const symbol = parts.find((part) => part.type === "currency")?.value;
104
+
105
+ return symbol;
106
+ }
107
+
108
+ /**
109
+ * Parse number
110
+ * @param rawData Raw data
111
+ */
112
+ export function parse(rawData: unknown): number | undefined;
113
+
114
+ /**
115
+ * Parse number with default value
116
+ * @param rawData Raw data
117
+ * @param defaultValue Default value
118
+ */
119
+ export function parse(rawData: unknown, defaultValue: number): number;
120
+
121
+ export function parse(
122
+ rawData: unknown,
123
+ defaultValue?: number
124
+ ): number | undefined {
125
+ if (rawData == null || rawData === "") {
126
+ return defaultValue;
67
127
  }
68
128
 
69
- /**
70
- * Format file size
71
- * @param size File size
72
- * @param fractionDigits Fraction digits
73
- * @returns Result
74
- */
75
- export function formatFileSize(size: number, fractionDigits: number = 2) {
76
- const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
77
- return (
78
- (size / Math.pow(1024, i)).toFixed(fractionDigits) +
79
- ' ' +
80
- ['B', 'KB', 'MB', 'GB', 'TB', 'PB'][i]
81
- );
129
+ if (typeof rawData === "number") {
130
+ if (isNaN(rawData)) return defaultValue;
131
+ return rawData;
82
132
  }
83
133
 
84
- /**
85
- * Get currency symbol or name from ISO code
86
- * @param code ISO currency code, like USD / CNY
87
- * @param display Display format
88
- * @param locale Locale
89
- * @returns Result
90
- */
91
- export function getCurrencySymbol(
92
- code: string,
93
- display: 'symbol' | 'narrowSymbol' | 'name' = 'narrowSymbol',
94
- locale?: string
95
- ): string | undefined {
96
- const formatter = new Intl.NumberFormat(locale, {
97
- style: 'currency',
98
- currency: code,
99
- currencyDisplay: display
100
- });
101
-
102
- const parts = formatter.formatToParts();
103
- const symbol = parts.find((part) => part.type === 'currency')?.value;
104
-
105
- return symbol;
134
+ const p = parseFloat(rawData.toString());
135
+ if (isNaN(p)) return defaultValue;
136
+ return p;
137
+ }
138
+
139
+ /**
140
+ * Parse float value and unit
141
+ * @param input Input string
142
+ * @returns Result, like [number, string]
143
+ */
144
+ export const parseWithUnit = (
145
+ input: string
146
+ ): [number, string] | undefined => {
147
+ if (/^(\d+)(\D*)$/g.test(input)) {
148
+ return [Number(RegExp.$1), RegExp.$2.trim()];
106
149
  }
107
-
108
- /**
109
- * Parse number
110
- * @param rawData Raw data
111
- */
112
- export function parse(rawData: unknown): number | undefined;
113
-
114
- /**
115
- * Parse number with default value
116
- * @param rawData Raw data
117
- * @param defaultValue Default value
118
- */
119
- export function parse(rawData: unknown, defaultValue: number): number;
120
-
121
- export function parse(
122
- rawData: unknown,
123
- defaultValue?: number
124
- ): number | undefined {
125
- if (rawData == null || rawData === '') {
126
- return defaultValue;
127
- }
128
-
129
- if (typeof rawData === 'number') {
130
- if (isNaN(rawData)) return defaultValue;
131
- return rawData;
132
- }
133
-
134
- const p = parseFloat(rawData.toString());
135
- if (isNaN(p)) return defaultValue;
136
- return p;
137
- }
138
-
139
- /**
140
- * Parse float value and unit
141
- * @param input Input string
142
- * @returns Result, like [number, string]
143
- */
144
- export const parseWithUnit = (
145
- input: string
146
- ): [number, string] | undefined => {
147
- if (/^(\d+)(\D*)$/g.test(input)) {
148
- return [Number(RegExp.$1), RegExp.$2.trim()];
149
- }
150
- return undefined;
151
- };
150
+ return undefined;
151
+ };
152
152
  }
@@ -1,5 +1,5 @@
1
- import { NodeStorage } from './node/Storage';
2
- import { Utils } from './Utils';
1
+ import { NodeStorage } from "./node/Storage";
2
+ import { Utils } from "./Utils";
3
3
 
4
4
  // Mock node
5
5
  globalThis.localStorage ??= new NodeStorage();
@@ -10,123 +10,123 @@ globalThis.sessionStorage ??= new NodeStorage();
10
10
  * NodeStorage needs data persistance
11
11
  */
12
12
  export namespace StorageUtils {
13
- /**
14
- * Set local storage data
15
- * @param key Key name
16
- * @param data Data, null for removal
17
- */
18
- export function setLocalData(key: string, data: unknown) {
19
- if (data == null) {
20
- localStorage.removeItem(key);
21
- return;
22
- }
23
-
24
- localStorage.setItem(
25
- key,
26
- typeof data === 'string' ? data : JSON.stringify(data)
27
- );
13
+ /**
14
+ * Set local storage data
15
+ * @param key Key name
16
+ * @param data Data, null for removal
17
+ */
18
+ export function setLocalData(key: string, data: unknown) {
19
+ if (data == null) {
20
+ localStorage.removeItem(key);
21
+ return;
28
22
  }
29
23
 
30
- /**
31
- * Set session storage data
32
- * @param key Key name
33
- * @param data Data, null for removal
34
- */
35
- export function setSessionData(key: string, data: unknown) {
36
- if (data == null) {
37
- sessionStorage.removeItem(key);
38
- return;
39
- }
40
-
41
- sessionStorage.setItem(
42
- key,
43
- typeof data === 'string' ? data : JSON.stringify(data)
44
- );
24
+ localStorage.setItem(
25
+ key,
26
+ typeof data === "string" ? data : JSON.stringify(data)
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Set session storage data
32
+ * @param key Key name
33
+ * @param data Data, null for removal
34
+ */
35
+ export function setSessionData(key: string, data: unknown) {
36
+ if (data == null) {
37
+ sessionStorage.removeItem(key);
38
+ return;
45
39
  }
46
40
 
47
- /**
48
- * Get local storage data
49
- * @param key Key name
50
- */
51
- export function getLocalData<T>(key: string): T | undefined;
52
-
53
- /**
54
- * Get local storage data
55
- * @param key Key name
56
- * @param defaultValue Default value
57
- */
58
- export function getLocalData<T>(key: string, defaultValue: T): T;
59
-
60
- /**
61
- * Get local storage data
62
- * @param key Key name
63
- * @param defaultValue Default value
64
- */
65
- export function getLocalData<T>(
66
- key: string,
67
- defaultValue?: T
68
- ): T | undefined {
69
- // Get storage
70
- const data = localStorage.getItem(key);
71
-
72
- // No default value
73
- if (defaultValue == null) return Utils.parseString<T>(data);
74
-
75
- // Return
76
- return Utils.parseString<T>(data, defaultValue);
77
- }
78
-
79
- /**
80
- * Get local storage object data
81
- * @param key Key name
82
- */
83
- export function getLocalObject<T extends object>(key: string) {
84
- // Get storage
85
- const data = localStorage.getItem(key);
86
- if (data == null) return undefined;
87
- return <T>JSON.parse(data);
88
- }
89
-
90
- /**
91
- * Get session storage data
92
- * @param key Key name
93
- */
94
- export function getSessionData<T>(key: string): T | undefined;
95
-
96
- /**
97
- * Get session storage data with default value
98
- * @param key Key name
99
- * @param defaultValue Default value
100
- */
101
- export function getSessionData<T>(key: string, defaultValue: T): T;
102
-
103
- /**
104
- * Get session storage data
105
- * @param key Key name
106
- * @param defaultValue Default value
107
- */
108
- export function getSessionData<T>(
109
- key: string,
110
- defaultValue?: T
111
- ): T | undefined {
112
- // Get storage
113
- const data = sessionStorage.getItem(key);
114
-
115
- // No default value
116
- if (defaultValue == null) return Utils.parseString<T>(data);
117
-
118
- // Return
119
- return Utils.parseString<T>(data, defaultValue);
120
- }
121
-
122
- /**
123
- * Get session storage object data
124
- * @param key Key name
125
- */
126
- export function getSessionObject<T extends object>(key: string) {
127
- // Get storage
128
- const data = sessionStorage.getItem(key);
129
- if (data == null) return undefined;
130
- return <T>JSON.parse(data);
131
- }
41
+ sessionStorage.setItem(
42
+ key,
43
+ typeof data === "string" ? data : JSON.stringify(data)
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Get local storage data
49
+ * @param key Key name
50
+ */
51
+ export function getLocalData<T>(key: string): T | undefined;
52
+
53
+ /**
54
+ * Get local storage data
55
+ * @param key Key name
56
+ * @param defaultValue Default value
57
+ */
58
+ export function getLocalData<T>(key: string, defaultValue: T): T;
59
+
60
+ /**
61
+ * Get local storage data
62
+ * @param key Key name
63
+ * @param defaultValue Default value
64
+ */
65
+ export function getLocalData<T>(
66
+ key: string,
67
+ defaultValue?: T
68
+ ): T | undefined {
69
+ // Get storage
70
+ const data = localStorage.getItem(key);
71
+
72
+ // No default value
73
+ if (defaultValue == null) return Utils.parseString<T>(data);
74
+
75
+ // Return
76
+ return Utils.parseString<T>(data, defaultValue);
77
+ }
78
+
79
+ /**
80
+ * Get local storage object data
81
+ * @param key Key name
82
+ */
83
+ export function getLocalObject<T extends object>(key: string) {
84
+ // Get storage
85
+ const data = localStorage.getItem(key);
86
+ if (data == null) return undefined;
87
+ return <T>JSON.parse(data);
88
+ }
89
+
90
+ /**
91
+ * Get session storage data
92
+ * @param key Key name
93
+ */
94
+ export function getSessionData<T>(key: string): T | undefined;
95
+
96
+ /**
97
+ * Get session storage data with default value
98
+ * @param key Key name
99
+ * @param defaultValue Default value
100
+ */
101
+ export function getSessionData<T>(key: string, defaultValue: T): T;
102
+
103
+ /**
104
+ * Get session storage data
105
+ * @param key Key name
106
+ * @param defaultValue Default value
107
+ */
108
+ export function getSessionData<T>(
109
+ key: string,
110
+ defaultValue?: T
111
+ ): T | undefined {
112
+ // Get storage
113
+ const data = sessionStorage.getItem(key);
114
+
115
+ // No default value
116
+ if (defaultValue == null) return Utils.parseString<T>(data);
117
+
118
+ // Return
119
+ return Utils.parseString<T>(data, defaultValue);
120
+ }
121
+
122
+ /**
123
+ * Get session storage object data
124
+ * @param key Key name
125
+ */
126
+ export function getSessionObject<T extends object>(key: string) {
127
+ // Get storage
128
+ const data = sessionStorage.getItem(key);
129
+ if (data == null) return undefined;
130
+ return <T>JSON.parse(data);
131
+ }
132
132
  }