@gateweb/react-utils 1.7.1 → 1.9.0
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/dist/cjs/index.d.ts +318 -150
- package/dist/cjs/index.js +666 -409
- package/dist/es/index.d.mts +318 -150
- package/dist/es/index.mjs +662 -411
- package/dist/es/{queryStore-client-CFQTVwrg.mjs → queryStore-client-vG-bXFYm.mjs} +1 -1
- package/package.json +2 -2
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,6 +2,130 @@ import { TExtractValueType, AtLeastOne } from './types.js';
|
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
|
|
5
|
+
declare const FILE_SIZE_UNITS: readonly ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
6
|
+
type FileSizeUnit = (typeof FILE_SIZE_UNITS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* 代表字節大小的類,提供各種格式化和轉換方法
|
|
9
|
+
*/
|
|
10
|
+
declare class ByteSize {
|
|
11
|
+
private readonly bytes;
|
|
12
|
+
/**
|
|
13
|
+
* 建立一個新的 ByteSize 實例
|
|
14
|
+
* @param bytes 位元組數值
|
|
15
|
+
*/
|
|
16
|
+
constructor(bytes: number);
|
|
17
|
+
/**
|
|
18
|
+
* 取得原始位元組數值
|
|
19
|
+
*/
|
|
20
|
+
get value(): number;
|
|
21
|
+
/**
|
|
22
|
+
* 將位元組轉換為指定單位的數值
|
|
23
|
+
*
|
|
24
|
+
* @param unit 目標單位 (例如 'KB', 'MB', 'GB')
|
|
25
|
+
* @returns 轉換後的數值
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const size = createByteSize(1024);
|
|
30
|
+
* size.to('KB'); // 1
|
|
31
|
+
* size.to('MB'); // 0.0009765625
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
to(unit: FileSizeUnit): number;
|
|
35
|
+
/**
|
|
36
|
+
* 轉換為適當單位的可讀字符串
|
|
37
|
+
*
|
|
38
|
+
* @param unit 指定單位 (例如 'KB', 'MB', 'GB'),不指定則自動選擇最適合的單位
|
|
39
|
+
* @param decimals 小數點位數 (預設為 2)
|
|
40
|
+
* @returns 格式化後的字符串
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const size = createByteSize(1024);
|
|
45
|
+
* size.format(); // '1.00 KB'
|
|
46
|
+
* size.format('KB'); // '1.00 KB'
|
|
47
|
+
* size.format('MB', 3); // '0.001 MB'
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
format(unit?: FileSizeUnit, decimals?: number): string;
|
|
51
|
+
/**
|
|
52
|
+
* 比較兩個 ByteSize 實例
|
|
53
|
+
*
|
|
54
|
+
* @param other 要比較的另一個 ByteSize 實例
|
|
55
|
+
* @returns 比較結果:-1 表示小於,0 表示等於,1 表示大於
|
|
56
|
+
*/
|
|
57
|
+
compareTo(other: ByteSize): number;
|
|
58
|
+
/**
|
|
59
|
+
* 轉換為字符串表示
|
|
60
|
+
* @returns 預設格式化的字符串
|
|
61
|
+
*/
|
|
62
|
+
toString(): string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 將位元組轉換為可讀字符串 (保留舊的 API 以確保向後兼容)
|
|
66
|
+
*
|
|
67
|
+
* @param bytes 位元組數值
|
|
68
|
+
* @param unit 目標單位 (例如 'KB', 'MB', 'GB'),不指定則自動選擇最適合的單位
|
|
69
|
+
* @param decimals 小數點位數 (預設為 2)
|
|
70
|
+
* @returns 格式化後的字符串
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* convertBytes(0) // '0 Bytes'
|
|
75
|
+
* convertBytes(1024, 'KB') // '1 KB'
|
|
76
|
+
* convertBytes(1024, 'KB', 2) // '1.00 KB'
|
|
77
|
+
* convertBytes(1024 * 1024, 'MB') // '1 MB'
|
|
78
|
+
* convertBytes(1024 * 1024, 'KB') // '1024 KB'
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare const convertBytes: (bytes: number, unit?: FileSizeUnit, decimals?: number) => string;
|
|
82
|
+
|
|
83
|
+
type SearchParamsObject = Record<string, string | number | boolean | null | undefined | (string | number | boolean)[]>;
|
|
84
|
+
/**
|
|
85
|
+
* 將單層物件轉換為 URLSearchParams 物件
|
|
86
|
+
* - 會自動排除 null、undefined、空字串和空陣列的值
|
|
87
|
+
* - 陣列會以逗號連接為字串
|
|
88
|
+
*
|
|
89
|
+
* @param obj - 要轉換的物件,只支援單層物件,其中值可以是 string、number、boolean、null、undefined 或字串陣列
|
|
90
|
+
* @returns URLSearchParams 實例
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* const params = { a: '1', b: 123, c: false, d: ['1','2'], e: null, f: undefined, g: '', h: [] };
|
|
94
|
+
* objectToSearchParams(params).toString(); // 'a=1&b=123&c=false&d=1%2C2'
|
|
95
|
+
*/
|
|
96
|
+
declare const objectToSearchParams: <T extends SearchParamsObject>(obj: T) => URLSearchParams;
|
|
97
|
+
/**
|
|
98
|
+
* 支援的型別轉換器類型
|
|
99
|
+
*/
|
|
100
|
+
type TypeConverter = 'string' | 'number' | 'boolean' | 'array';
|
|
101
|
+
/**
|
|
102
|
+
* 型別轉換映射表
|
|
103
|
+
*/
|
|
104
|
+
type TypeConverterMap<T extends object = Record<string, unknown>> = {
|
|
105
|
+
[K in keyof T]?: TypeConverter;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* 將 URLSearchParams 或字串轉換為物件
|
|
109
|
+
*
|
|
110
|
+
* @param searchParams - 要轉換的搜尋參數字串或 URLSearchParams 實例
|
|
111
|
+
* @param typeMap - 可選的型別轉換映射表,用於指定每個參數的目標型別
|
|
112
|
+
* @returns
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const queryString = 'a=1&b=123&c=true&d=1,2,3&e=false';
|
|
116
|
+
* const result = searchParamsToObject(queryString);
|
|
117
|
+
* // result: { a: '1', b: '123', c: 'true', d: '1,2,3', e: 'false' }
|
|
118
|
+
* const result = searchParamsToObject(queryString, {
|
|
119
|
+
* a: 'string',
|
|
120
|
+
* b: 'number',
|
|
121
|
+
* c: 'boolean',
|
|
122
|
+
* d: 'array',
|
|
123
|
+
* e: 'boolean',
|
|
124
|
+
* });
|
|
125
|
+
* // result: { a: '1', b: 123, c: true, d: ['1', '2', '3'], e: false }
|
|
126
|
+
*/
|
|
127
|
+
declare const searchParamsToObject: <T extends object = SearchParamsObject>(searchParams: string | URLSearchParams, typeMap?: TypeConverterMap<T>) => Partial<T>;
|
|
128
|
+
|
|
5
129
|
type CamelToPascal<S extends string> = S extends `${infer Head}${infer Tail}` ? `${Uppercase<Head>}${Tail}` : S;
|
|
6
130
|
/**
|
|
7
131
|
* convert CamelCase string to PascalCase string
|
|
@@ -158,54 +282,89 @@ declare const snakeCase2CamelCase: <T extends Record<string, any>>(obj: T) => Tr
|
|
|
158
282
|
declare const snakeCase2PascalCase: <T extends Record<string, any>>(obj: T) => TransformObjectKey<T, "SnakeToPascal">;
|
|
159
283
|
|
|
160
284
|
/**
|
|
161
|
-
*
|
|
285
|
+
* 將數字轉換成金額千分位格式
|
|
286
|
+
*
|
|
287
|
+
* @param num - 數字
|
|
162
288
|
*
|
|
163
289
|
* @example
|
|
164
|
-
*
|
|
165
|
-
*
|
|
290
|
+
*
|
|
291
|
+
* formatAmount(1234567) // '1,234,567'
|
|
166
292
|
*/
|
|
167
|
-
declare const
|
|
293
|
+
declare const formatAmount: (num: number) => string;
|
|
168
294
|
/**
|
|
169
|
-
*
|
|
295
|
+
* 將字串的第 n - m 個字轉換成星號
|
|
170
296
|
*
|
|
171
|
-
*
|
|
297
|
+
* @param str - 字串
|
|
298
|
+
* @param n - 起始位置
|
|
299
|
+
* @param m - 結束位置
|
|
172
300
|
*
|
|
173
|
-
*
|
|
301
|
+
* @example
|
|
174
302
|
*
|
|
175
|
-
*
|
|
303
|
+
* formatString('123456', 1, 4) // '1****6'
|
|
304
|
+
*
|
|
305
|
+
* @deprecated use `maskString` instead
|
|
306
|
+
*/
|
|
307
|
+
declare const formatStarMask: (str: string, n: number, m: number) => string;
|
|
308
|
+
/**
|
|
309
|
+
* 將字串的指定位置的以後的字元轉換成星號
|
|
310
|
+
*
|
|
311
|
+
* @param str 字串
|
|
312
|
+
* @param start 起始位置 (從 0 開始計算)
|
|
313
|
+
* @param length 可選,從起始位置開始要遮罩的字元數量,默認為剩餘所有字元
|
|
176
314
|
*
|
|
177
315
|
* @example
|
|
178
316
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* //
|
|
182
|
-
*
|
|
183
|
-
* //
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* getCurrentPeriod() // 11104
|
|
317
|
+
* ```js
|
|
318
|
+
* maskString('123456789', 2) // '12*******'
|
|
319
|
+
* maskString('123456789', 2, 5) // '12*****89'
|
|
320
|
+
* maskString('123456789', 0, 15) // '*********'
|
|
321
|
+
* maskString('123456789', 10) // '123456789' (start out of bounds)
|
|
322
|
+
* maskString('123456789', -1) // '123456789' (start out of bounds)
|
|
323
|
+
* ```
|
|
187
324
|
*/
|
|
188
|
-
declare const
|
|
325
|
+
declare const maskString: (str: string, start: number, length?: number) => string;
|
|
189
326
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
327
|
+
* format file size to human readable string
|
|
328
|
+
*
|
|
329
|
+
* it will convert bytes to KB, MB, GB, TB, PB, EB, ZB, YB
|
|
330
|
+
*
|
|
331
|
+
* @param bytes file size in bytes
|
|
332
|
+
* @param decimals number of decimal places (default is 2)
|
|
333
|
+
*
|
|
193
334
|
* @example
|
|
194
335
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
336
|
+
* ```js
|
|
337
|
+
* formatBytes(0) // 0 Bytes
|
|
338
|
+
* formatBytes(1024) // 1 KB
|
|
339
|
+
* formatBytes(1024, 2) // 1.00 KB
|
|
340
|
+
* formatBytes(1024 * 1024) // 1 MB
|
|
341
|
+
* ```
|
|
342
|
+
* @deprecated use `convertBytes` instead
|
|
197
343
|
*/
|
|
198
|
-
declare const
|
|
344
|
+
declare const formatBytes: (bytes: number, decimals?: number) => string;
|
|
345
|
+
|
|
199
346
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
347
|
+
* 檢查兩個值是否相等(包含陣列等引用型別)
|
|
348
|
+
* - 支援基本型別的直接比較
|
|
349
|
+
* - 特別處理空陣列比較
|
|
350
|
+
* - 支援非空陣列的深度比較
|
|
204
351
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
352
|
+
* @param value1 - 第一個值
|
|
353
|
+
* @param value2 - 第二個值
|
|
354
|
+
* @returns 如果值相等則返回 true
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* // 基本型別比較
|
|
358
|
+
* isEqual(1, 1); // true
|
|
359
|
+
* isEqual('abc', 'abc'); // true
|
|
360
|
+
* isEqual(null, null); // true
|
|
361
|
+
*
|
|
362
|
+
* // 陣列比較
|
|
363
|
+
* isEqual([], []); // true
|
|
364
|
+
* isEqual([1, 2], [1, 2]); // true
|
|
365
|
+
* isEqual([1, 2], [1, 3]); // false
|
|
207
366
|
*/
|
|
208
|
-
declare const
|
|
367
|
+
declare const isEqual: (value1: unknown, value2: unknown) => boolean;
|
|
209
368
|
|
|
210
369
|
/**
|
|
211
370
|
* 將指定格式的物件轉換成類似 enum 的物件
|
|
@@ -323,53 +482,6 @@ declare const validateFileType: (file: File, accepts: string[]) => boolean;
|
|
|
323
482
|
*/
|
|
324
483
|
declare const getMimeType: (fileName: string) => "image/jpeg" | "image/png" | "application/pdf" | "application/zip" | "text/csv" | "text/plain" | "application/octet-stream";
|
|
325
484
|
|
|
326
|
-
type TCountdownActions = {
|
|
327
|
-
/** 目前秒數 */
|
|
328
|
-
countdown: number;
|
|
329
|
-
/** 是否正在倒數計時 */
|
|
330
|
-
isCounting: boolean;
|
|
331
|
-
/** 開始倒數計時 */
|
|
332
|
-
start: () => void;
|
|
333
|
-
/** 停止倒數計時 */
|
|
334
|
-
stop: () => void;
|
|
335
|
-
/** 重置倒數計時 */
|
|
336
|
-
reset: () => void;
|
|
337
|
-
};
|
|
338
|
-
/**
|
|
339
|
-
* 倒數計時器
|
|
340
|
-
*
|
|
341
|
-
* 可以透過 start() 來啟動倒數計時器
|
|
342
|
-
* 可以透過 stop() 來停止倒數計時器
|
|
343
|
-
* 可以透過 reset() 來重置倒數計時器
|
|
344
|
-
*
|
|
345
|
-
* @param initialCountdown 倒數計時器初始值
|
|
346
|
-
* @param enableReinitialize 允許重設初始值
|
|
347
|
-
*/
|
|
348
|
-
declare const useCountdown: (initialCountdown: number, enableReinitialize?: boolean) => TCountdownActions;
|
|
349
|
-
|
|
350
|
-
type TValueOptions<T> = AtLeastOne<{
|
|
351
|
-
/**
|
|
352
|
-
* The controlled value.
|
|
353
|
-
*/
|
|
354
|
-
value?: T;
|
|
355
|
-
/**
|
|
356
|
-
* The default value.
|
|
357
|
-
*/
|
|
358
|
-
defaultValue?: T;
|
|
359
|
-
}>;
|
|
360
|
-
/**
|
|
361
|
-
* A hook to manage a value.
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
*
|
|
365
|
-
* ```tsx
|
|
366
|
-
* const MyComponent = ({ value }: { value?: number }) => {
|
|
367
|
-
* const [currentValue, setCurrentValue] = useValue({ value });
|
|
368
|
-
* };
|
|
369
|
-
* ```
|
|
370
|
-
*/
|
|
371
|
-
declare const useValue: <T>({ value, defaultValue }: TValueOptions<T>) => readonly [T, (newValue: T) => void];
|
|
372
|
-
|
|
373
485
|
declare function invariant(condition: any, message?: string | (() => string)): asserts condition;
|
|
374
486
|
|
|
375
487
|
/**
|
|
@@ -395,8 +507,8 @@ declare const omit: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
|
|
|
395
507
|
* @param values 要排除的 value
|
|
396
508
|
*
|
|
397
509
|
* @example
|
|
398
|
-
* const a = { a: undefined, b: null, c: 3, d: 4 };
|
|
399
|
-
* const b = omitByValue(a, undefined, null); // { c: 3, d: 4 }
|
|
510
|
+
* const a = { a: undefined, b: null, c: 3, d: 4, e: [] };
|
|
511
|
+
* const b = omitByValue(a, undefined, null, []); // { c: 3, d: 4 }
|
|
400
512
|
*/
|
|
401
513
|
declare const omitByValue: <T extends object, K extends any[]>(object: T, ...values: K) => Pick<T, { [K2 in keyof T]: T[K2] extends K[number] ? never : K2; }[keyof T]>;
|
|
402
514
|
/**
|
|
@@ -419,8 +531,8 @@ declare const pick: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
|
|
|
419
531
|
*
|
|
420
532
|
* @example
|
|
421
533
|
*
|
|
422
|
-
* const a = { a: 1, b: 2, c: 3, d: 4 };
|
|
423
|
-
* const b = pickByValue(a, 1, 2); // { a: 1, b: 2 }
|
|
534
|
+
* const a = { a: 1, b: 2, c: 3, d: 4, e: [] };
|
|
535
|
+
* const b = pickByValue(a, 1, 2, []); // { a: 1, b: 2, e: [] }
|
|
424
536
|
*/
|
|
425
537
|
declare const pickByValue: <T extends object, K extends any[]>(object: T, ...values: K) => Pick<T, { [K2 in keyof T]: T[K2] extends K[number] ? K2 : never; }[keyof T]>;
|
|
426
538
|
/**
|
|
@@ -503,7 +615,11 @@ declare const debounce: <P, R>(fn: (...args: P[]) => R, delay: number) => (...ar
|
|
|
503
615
|
*/
|
|
504
616
|
declare const throttle: <P, R>(fn: (...args: P[]) => R, delay: number) => (...args: P[]) => R | undefined;
|
|
505
617
|
|
|
506
|
-
|
|
618
|
+
/**
|
|
619
|
+
* Wait for a given amount of time
|
|
620
|
+
* @param ms time to wait in milliseconds
|
|
621
|
+
*/
|
|
622
|
+
declare const wait: (ms: number) => void;
|
|
507
623
|
|
|
508
624
|
/**
|
|
509
625
|
* 中文
|
|
@@ -737,6 +853,50 @@ declare const isTWMobile: () => RegExp;
|
|
|
737
853
|
*/
|
|
738
854
|
declare const isTWPhone: () => RegExp;
|
|
739
855
|
|
|
856
|
+
/**
|
|
857
|
+
* 檢查稅務編號是否符合正確的編號規則。
|
|
858
|
+
*
|
|
859
|
+
* @param {string} taxId - 要檢查的8位數稅務編號。
|
|
860
|
+
* @returns {boolean} - 如果符合規則則返回 true,否則返回 false。
|
|
861
|
+
*
|
|
862
|
+
* ### 編號檢查規則:
|
|
863
|
+
* 1. **基本格式檢查**:
|
|
864
|
+
* - 編號必須為 8 位數字。
|
|
865
|
+
* - 不得為「00000000」或「11111111」,這些編號被視為無效。
|
|
866
|
+
*
|
|
867
|
+
* 2. **驗證邏輯**:
|
|
868
|
+
* - 使用一組驗證運算子:`[1, 2, 1, 2, 1, 2, 4, 1]`。
|
|
869
|
+
* - 將稅務編號的每一位數字與對應的運算子相乘後,使用 `calculate` 函數計算各位數的和。
|
|
870
|
+
* - 計算公式為:`(product % 10) + (product - (product % 10)) / 10`
|
|
871
|
+
* - 將所有位數經計算後的結果加總為 `sum`。
|
|
872
|
+
*
|
|
873
|
+
* 3. **檢查規則**:
|
|
874
|
+
* - 如果總和 `sum` 可以被 5 整除,則編號有效。
|
|
875
|
+
* - 或者,若第七位數為 7,且 `(sum + 1) % 5 === 0`,則編號有效。
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
*
|
|
879
|
+
* validTaxId('22099131') // true
|
|
880
|
+
* validTaxId('84149961') // true
|
|
881
|
+
* validTaxId('00000000') // false
|
|
882
|
+
* validTaxId('11111111') // false
|
|
883
|
+
* validTaxId('22099132') // false
|
|
884
|
+
*/
|
|
885
|
+
declare const validTaxId: (taxId: string) => boolean;
|
|
886
|
+
/**
|
|
887
|
+
* 驗證日期格式是否正確
|
|
888
|
+
*
|
|
889
|
+
* @param dateString 日期字串
|
|
890
|
+
* @param format 日期格式
|
|
891
|
+
* @example
|
|
892
|
+
*
|
|
893
|
+
* validateDateString('20210201', 'YYYYMMDD') // true
|
|
894
|
+
* validateDateString('2021-02-01', 'YYYY-MM-DD') // true
|
|
895
|
+
* validateDateString('20210201', 'YYYY-MM-DD') // false
|
|
896
|
+
* validateDateString('20210201', 'YYYYMM') // false
|
|
897
|
+
*/
|
|
898
|
+
declare const validateDateString: (dateString: string, format: string) => boolean;
|
|
899
|
+
|
|
740
900
|
type TQueryProps<Q> = {
|
|
741
901
|
/**
|
|
742
902
|
* the query object
|
|
@@ -787,96 +947,105 @@ declare const QueryProvider: <Q>({ children, query, handleChangeQuery, }: React.
|
|
|
787
947
|
*/
|
|
788
948
|
declare const useQueryContext: <Q>() => <T>(selector: (state: TQueryState<Q>) => T, equalityFn?: (left: T, right: T) => boolean) => T;
|
|
789
949
|
|
|
950
|
+
type TCountdownActions = {
|
|
951
|
+
/** 目前秒數 */
|
|
952
|
+
countdown: number;
|
|
953
|
+
/** 是否正在倒數計時 */
|
|
954
|
+
isCounting: boolean;
|
|
955
|
+
/** 開始倒數計時 */
|
|
956
|
+
start: () => void;
|
|
957
|
+
/** 停止倒數計時 */
|
|
958
|
+
stop: () => void;
|
|
959
|
+
/** 重置倒數計時 */
|
|
960
|
+
reset: () => void;
|
|
961
|
+
};
|
|
790
962
|
/**
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
* @param num - 數字
|
|
794
|
-
*
|
|
795
|
-
* @example
|
|
796
|
-
*
|
|
797
|
-
* formatAmount(1234567) // '1,234,567'
|
|
798
|
-
*/
|
|
799
|
-
declare const formatAmount: (num: number) => string;
|
|
800
|
-
/**
|
|
801
|
-
* 將字串的第 n - m 個字轉換成星號
|
|
802
|
-
*
|
|
803
|
-
* @param str - 字串
|
|
804
|
-
* @param n - 起始位置
|
|
805
|
-
* @param m - 結束位置
|
|
963
|
+
* 倒數計時器
|
|
806
964
|
*
|
|
807
|
-
*
|
|
965
|
+
* 可以透過 start() 來啟動倒數計時器
|
|
966
|
+
* 可以透過 stop() 來停止倒數計時器
|
|
967
|
+
* 可以透過 reset() 來重置倒數計時器
|
|
808
968
|
*
|
|
809
|
-
*
|
|
969
|
+
* @param initialCountdown 倒數計時器初始值
|
|
970
|
+
* @param enableReinitialize 允許重設初始值
|
|
810
971
|
*/
|
|
811
|
-
declare const
|
|
972
|
+
declare const useCountdown: (initialCountdown: number, enableReinitialize?: boolean) => TCountdownActions;
|
|
973
|
+
|
|
974
|
+
type TValueOptions<T> = AtLeastOne<{
|
|
975
|
+
/**
|
|
976
|
+
* The controlled value.
|
|
977
|
+
*/
|
|
978
|
+
value?: T;
|
|
979
|
+
/**
|
|
980
|
+
* The default value.
|
|
981
|
+
*/
|
|
982
|
+
defaultValue?: T;
|
|
983
|
+
}>;
|
|
812
984
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
* it will convert bytes to KB, MB, GB, TB, PB, EB, ZB, YB
|
|
816
|
-
*
|
|
817
|
-
* @param bytes file size in bytes
|
|
818
|
-
* @param decimals number of decimal places (default is 2)
|
|
985
|
+
* A hook to manage a value.
|
|
819
986
|
*
|
|
820
987
|
* @example
|
|
821
988
|
*
|
|
822
|
-
* ```
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
* formatBytes(1024 * 1024) // 1 MB
|
|
989
|
+
* ```tsx
|
|
990
|
+
* const MyComponent = ({ value }: { value?: number }) => {
|
|
991
|
+
* const [currentValue, setCurrentValue] = useValue({ value });
|
|
992
|
+
* };
|
|
827
993
|
* ```
|
|
828
994
|
*/
|
|
829
|
-
declare const
|
|
995
|
+
declare const useValue: <T>({ value, defaultValue }: TValueOptions<T>) => readonly [T, (newValue: T) => void];
|
|
996
|
+
|
|
997
|
+
declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>): React.RefCallback<T>;
|
|
830
998
|
|
|
831
999
|
/**
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
* @param
|
|
835
|
-
* @returns {boolean} - 如果符合規則則返回 true,否則返回 false。
|
|
836
|
-
*
|
|
837
|
-
* ### 編號檢查規則:
|
|
838
|
-
* 1. **基本格式檢查**:
|
|
839
|
-
* - 編號必須為 8 位數字。
|
|
840
|
-
* - 不得為「00000000」或「11111111」,這些編號被視為無效。
|
|
841
|
-
*
|
|
842
|
-
* 2. **驗證邏輯**:
|
|
843
|
-
* - 使用一組驗證運算子:`[1, 2, 1, 2, 1, 2, 4, 1]`。
|
|
844
|
-
* - 將稅務編號的每一位數字與對應的運算子相乘後,使用 `calculate` 函數計算各位數的和。
|
|
845
|
-
* - 計算公式為:`(product % 10) + (product - (product % 10)) / 10`
|
|
846
|
-
* - 將所有位數經計算後的結果加總為 `sum`。
|
|
847
|
-
*
|
|
848
|
-
* 3. **檢查規則**:
|
|
849
|
-
* - 如果總和 `sum` 可以被 5 整除,則編號有效。
|
|
850
|
-
* - 或者,若第七位數為 7,且 `(sum + 1) % 5 === 0`,則編號有效。
|
|
851
|
-
*
|
|
1000
|
+
* 民國年轉西元年
|
|
1001
|
+
* @param dateString 日期字串
|
|
1002
|
+
* @param format 日期格式
|
|
852
1003
|
* @example
|
|
853
1004
|
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
* validTaxId('00000000') // false
|
|
857
|
-
* validTaxId('11111111') // false
|
|
858
|
-
* validTaxId('22099132') // false
|
|
1005
|
+
* rocEraToAd('1100201') // 20210201
|
|
1006
|
+
* rocEraToAd('11002', 'YYYYMM') // 202102
|
|
859
1007
|
*/
|
|
860
|
-
declare const
|
|
1008
|
+
declare const rocEraToAd: (dateString: string, format?: string) => string;
|
|
861
1009
|
/**
|
|
862
|
-
*
|
|
863
|
-
*
|
|
1010
|
+
* 西元年轉民國年
|
|
864
1011
|
* @param dateString 日期字串
|
|
865
1012
|
* @param format 日期格式
|
|
866
1013
|
* @example
|
|
867
1014
|
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* validateDateString('20210201', 'YYYY-MM-DD') // false
|
|
871
|
-
* validateDateString('20210201', 'YYYYMM') // false
|
|
1015
|
+
* adToRocEra('20210201') // 1100201
|
|
1016
|
+
* adToRocEra('202102', 'YYYYMM') // 11002
|
|
872
1017
|
*/
|
|
873
|
-
declare const
|
|
1018
|
+
declare const adToRocEra: (dateString: string, format?: string) => string;
|
|
874
1019
|
|
|
875
1020
|
/**
|
|
876
|
-
*
|
|
877
|
-
*
|
|
1021
|
+
* 取得去年今年以及明年期別陣列
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* // 假設 今年為 112 年
|
|
1025
|
+
* generatePeriodArray() // 11102 ~ 11312
|
|
878
1026
|
*/
|
|
879
|
-
declare const
|
|
1027
|
+
declare const generatePeriodArray: () => string[];
|
|
1028
|
+
/**
|
|
1029
|
+
* 取得當前期別
|
|
1030
|
+
*
|
|
1031
|
+
* 報稅期限次期開始15日內
|
|
1032
|
+
*
|
|
1033
|
+
* 雙數月沒有特殊規則,期別皆為當月開頭
|
|
1034
|
+
*
|
|
1035
|
+
* 單數月15號以前,期別為上個月否則為下個月開頭
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
*
|
|
1039
|
+
* // 假設今天是 111-02-15
|
|
1040
|
+
* getCurrentPeriod() // 11102
|
|
1041
|
+
* // 假設今天是 111-02-16
|
|
1042
|
+
* getCurrentPeriod() // 11102
|
|
1043
|
+
* // 假設今天是 111-03-15
|
|
1044
|
+
* getCurrentPeriod() // 11102
|
|
1045
|
+
* // 假設今天是 111-03-16
|
|
1046
|
+
* getCurrentPeriod() // 11104
|
|
1047
|
+
*/
|
|
1048
|
+
declare const getCurrentPeriod: () => string;
|
|
880
1049
|
|
|
881
1050
|
/**
|
|
882
1051
|
* Downloads a file from a given source.
|
|
@@ -911,5 +1080,4 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
911
1080
|
*/
|
|
912
1081
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
913
1082
|
|
|
914
|
-
export { QueryProvider, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, createEnumLikeObject, debounce, deepMerge, downloadFile, extractEnumLikeObject, fakeApi, formatAmount, formatBytes, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, isValidPassword, mergeRefs, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, pick, pickByValue, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, useQueryContext, useValue, validTaxId, validateDateString, validateFileType, wait };
|
|
915
|
-
export type { PartialBy, RequiredBy, TCountdownActions };
|
|
1083
|
+
export { ByteSize, type PartialBy, QueryProvider, type RequiredBy, type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, convertBytes, createEnumLikeObject, debounce, deepMerge, downloadFile, extractEnumLikeObject, fakeApi, formatAmount, formatBytes, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isEqual, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, isValidPassword, maskString, mergeRefs, objectToSearchParams, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, pick, pickByValue, rocEraToAd, searchParamsToObject, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, useQueryContext, useValue, validTaxId, validateDateString, validateFileType, wait };
|