@gateweb/react-utils 1.7.1 → 1.8.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 +300 -152
- package/dist/cjs/index.js +630 -398
- package/dist/es/index.d.mts +300 -152
- package/dist/es/index.mjs +627 -400
- 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,69 @@ 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
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* 報稅期限次期開始15日內
|
|
172
|
-
*
|
|
173
|
-
* 雙數月沒有特殊規則,期別皆為當月開頭
|
|
295
|
+
* 將字串的第 n - m 個字轉換成星號
|
|
174
296
|
*
|
|
175
|
-
*
|
|
297
|
+
* @param str - 字串
|
|
298
|
+
* @param n - 起始位置
|
|
299
|
+
* @param m - 結束位置
|
|
176
300
|
*
|
|
177
301
|
* @example
|
|
178
302
|
*
|
|
179
|
-
* //
|
|
180
|
-
* getCurrentPeriod() // 11102
|
|
181
|
-
* // 假設今天是 111-02-16
|
|
182
|
-
* getCurrentPeriod() // 11102
|
|
183
|
-
* // 假設今天是 111-03-15
|
|
184
|
-
* getCurrentPeriod() // 11102
|
|
185
|
-
* // 假設今天是 111-03-16
|
|
186
|
-
* getCurrentPeriod() // 11104
|
|
303
|
+
* formatString('123456', 1, 4) // '1****6'
|
|
187
304
|
*/
|
|
188
|
-
declare const
|
|
305
|
+
declare const formatStarMask: (str: string, n: number, m: number) => string;
|
|
189
306
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
307
|
+
* format file size to human readable string
|
|
308
|
+
*
|
|
309
|
+
* it will convert bytes to KB, MB, GB, TB, PB, EB, ZB, YB
|
|
310
|
+
*
|
|
311
|
+
* @param bytes file size in bytes
|
|
312
|
+
* @param decimals number of decimal places (default is 2)
|
|
313
|
+
*
|
|
193
314
|
* @example
|
|
194
315
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
316
|
+
* ```js
|
|
317
|
+
* formatBytes(0) // 0 Bytes
|
|
318
|
+
* formatBytes(1024) // 1 KB
|
|
319
|
+
* formatBytes(1024, 2) // 1.00 KB
|
|
320
|
+
* formatBytes(1024 * 1024) // 1 MB
|
|
321
|
+
* ```
|
|
322
|
+
* @deprecated use `convertBytes` instead
|
|
197
323
|
*/
|
|
198
|
-
declare const
|
|
324
|
+
declare const formatBytes: (bytes: number, decimals?: number) => string;
|
|
325
|
+
|
|
199
326
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
327
|
+
* 檢查兩個值是否相等(包含陣列等引用型別)
|
|
328
|
+
* - 支援基本型別的直接比較
|
|
329
|
+
* - 特別處理空陣列比較
|
|
330
|
+
* - 支援非空陣列的深度比較
|
|
204
331
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
332
|
+
* @param value1 - 第一個值
|
|
333
|
+
* @param value2 - 第二個值
|
|
334
|
+
* @returns 如果值相等則返回 true
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* // 基本型別比較
|
|
338
|
+
* isEqual(1, 1); // true
|
|
339
|
+
* isEqual('abc', 'abc'); // true
|
|
340
|
+
* isEqual(null, null); // true
|
|
341
|
+
*
|
|
342
|
+
* // 陣列比較
|
|
343
|
+
* isEqual([], []); // true
|
|
344
|
+
* isEqual([1, 2], [1, 2]); // true
|
|
345
|
+
* isEqual([1, 2], [1, 3]); // false
|
|
207
346
|
*/
|
|
208
|
-
declare const
|
|
347
|
+
declare const isEqual: (value1: unknown, value2: unknown) => boolean;
|
|
209
348
|
|
|
210
349
|
/**
|
|
211
350
|
* 將指定格式的物件轉換成類似 enum 的物件
|
|
@@ -323,53 +462,6 @@ declare const validateFileType: (file: File, accepts: string[]) => boolean;
|
|
|
323
462
|
*/
|
|
324
463
|
declare const getMimeType: (fileName: string) => "image/jpeg" | "image/png" | "application/pdf" | "application/zip" | "text/csv" | "text/plain" | "application/octet-stream";
|
|
325
464
|
|
|
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
465
|
declare function invariant(condition: any, message?: string | (() => string)): asserts condition;
|
|
374
466
|
|
|
375
467
|
/**
|
|
@@ -395,8 +487,8 @@ declare const omit: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
|
|
|
395
487
|
* @param values 要排除的 value
|
|
396
488
|
*
|
|
397
489
|
* @example
|
|
398
|
-
* const a = { a: undefined, b: null, c: 3, d: 4 };
|
|
399
|
-
* const b = omitByValue(a, undefined, null); // { c: 3, d: 4 }
|
|
490
|
+
* const a = { a: undefined, b: null, c: 3, d: 4, e: [] };
|
|
491
|
+
* const b = omitByValue(a, undefined, null, []); // { c: 3, d: 4 }
|
|
400
492
|
*/
|
|
401
493
|
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
494
|
/**
|
|
@@ -419,8 +511,8 @@ declare const pick: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
|
|
|
419
511
|
*
|
|
420
512
|
* @example
|
|
421
513
|
*
|
|
422
|
-
* const a = { a: 1, b: 2, c: 3, d: 4 };
|
|
423
|
-
* const b = pickByValue(a, 1, 2); // { a: 1, b: 2 }
|
|
514
|
+
* const a = { a: 1, b: 2, c: 3, d: 4, e: [] };
|
|
515
|
+
* const b = pickByValue(a, 1, 2, []); // { a: 1, b: 2, e: [] }
|
|
424
516
|
*/
|
|
425
517
|
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
518
|
/**
|
|
@@ -503,7 +595,11 @@ declare const debounce: <P, R>(fn: (...args: P[]) => R, delay: number) => (...ar
|
|
|
503
595
|
*/
|
|
504
596
|
declare const throttle: <P, R>(fn: (...args: P[]) => R, delay: number) => (...args: P[]) => R | undefined;
|
|
505
597
|
|
|
506
|
-
|
|
598
|
+
/**
|
|
599
|
+
* Wait for a given amount of time
|
|
600
|
+
* @param ms time to wait in milliseconds
|
|
601
|
+
*/
|
|
602
|
+
declare const wait: (ms: number) => void;
|
|
507
603
|
|
|
508
604
|
/**
|
|
509
605
|
* 中文
|
|
@@ -737,6 +833,50 @@ declare const isTWMobile: () => RegExp;
|
|
|
737
833
|
*/
|
|
738
834
|
declare const isTWPhone: () => RegExp;
|
|
739
835
|
|
|
836
|
+
/**
|
|
837
|
+
* 檢查稅務編號是否符合正確的編號規則。
|
|
838
|
+
*
|
|
839
|
+
* @param {string} taxId - 要檢查的8位數稅務編號。
|
|
840
|
+
* @returns {boolean} - 如果符合規則則返回 true,否則返回 false。
|
|
841
|
+
*
|
|
842
|
+
* ### 編號檢查規則:
|
|
843
|
+
* 1. **基本格式檢查**:
|
|
844
|
+
* - 編號必須為 8 位數字。
|
|
845
|
+
* - 不得為「00000000」或「11111111」,這些編號被視為無效。
|
|
846
|
+
*
|
|
847
|
+
* 2. **驗證邏輯**:
|
|
848
|
+
* - 使用一組驗證運算子:`[1, 2, 1, 2, 1, 2, 4, 1]`。
|
|
849
|
+
* - 將稅務編號的每一位數字與對應的運算子相乘後,使用 `calculate` 函數計算各位數的和。
|
|
850
|
+
* - 計算公式為:`(product % 10) + (product - (product % 10)) / 10`
|
|
851
|
+
* - 將所有位數經計算後的結果加總為 `sum`。
|
|
852
|
+
*
|
|
853
|
+
* 3. **檢查規則**:
|
|
854
|
+
* - 如果總和 `sum` 可以被 5 整除,則編號有效。
|
|
855
|
+
* - 或者,若第七位數為 7,且 `(sum + 1) % 5 === 0`,則編號有效。
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
*
|
|
859
|
+
* validTaxId('22099131') // true
|
|
860
|
+
* validTaxId('84149961') // true
|
|
861
|
+
* validTaxId('00000000') // false
|
|
862
|
+
* validTaxId('11111111') // false
|
|
863
|
+
* validTaxId('22099132') // false
|
|
864
|
+
*/
|
|
865
|
+
declare const validTaxId: (taxId: string) => boolean;
|
|
866
|
+
/**
|
|
867
|
+
* 驗證日期格式是否正確
|
|
868
|
+
*
|
|
869
|
+
* @param dateString 日期字串
|
|
870
|
+
* @param format 日期格式
|
|
871
|
+
* @example
|
|
872
|
+
*
|
|
873
|
+
* validateDateString('20210201', 'YYYYMMDD') // true
|
|
874
|
+
* validateDateString('2021-02-01', 'YYYY-MM-DD') // true
|
|
875
|
+
* validateDateString('20210201', 'YYYY-MM-DD') // false
|
|
876
|
+
* validateDateString('20210201', 'YYYYMM') // false
|
|
877
|
+
*/
|
|
878
|
+
declare const validateDateString: (dateString: string, format: string) => boolean;
|
|
879
|
+
|
|
740
880
|
type TQueryProps<Q> = {
|
|
741
881
|
/**
|
|
742
882
|
* the query object
|
|
@@ -787,96 +927,105 @@ declare const QueryProvider: <Q>({ children, query, handleChangeQuery, }: React.
|
|
|
787
927
|
*/
|
|
788
928
|
declare const useQueryContext: <Q>() => <T>(selector: (state: TQueryState<Q>) => T, equalityFn?: (left: T, right: T) => boolean) => T;
|
|
789
929
|
|
|
930
|
+
type TCountdownActions = {
|
|
931
|
+
/** 目前秒數 */
|
|
932
|
+
countdown: number;
|
|
933
|
+
/** 是否正在倒數計時 */
|
|
934
|
+
isCounting: boolean;
|
|
935
|
+
/** 開始倒數計時 */
|
|
936
|
+
start: () => void;
|
|
937
|
+
/** 停止倒數計時 */
|
|
938
|
+
stop: () => void;
|
|
939
|
+
/** 重置倒數計時 */
|
|
940
|
+
reset: () => void;
|
|
941
|
+
};
|
|
790
942
|
/**
|
|
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 - 結束位置
|
|
943
|
+
* 倒數計時器
|
|
806
944
|
*
|
|
807
|
-
*
|
|
945
|
+
* 可以透過 start() 來啟動倒數計時器
|
|
946
|
+
* 可以透過 stop() 來停止倒數計時器
|
|
947
|
+
* 可以透過 reset() 來重置倒數計時器
|
|
808
948
|
*
|
|
809
|
-
*
|
|
949
|
+
* @param initialCountdown 倒數計時器初始值
|
|
950
|
+
* @param enableReinitialize 允許重設初始值
|
|
810
951
|
*/
|
|
811
|
-
declare const
|
|
952
|
+
declare const useCountdown: (initialCountdown: number, enableReinitialize?: boolean) => TCountdownActions;
|
|
953
|
+
|
|
954
|
+
type TValueOptions<T> = AtLeastOne<{
|
|
955
|
+
/**
|
|
956
|
+
* The controlled value.
|
|
957
|
+
*/
|
|
958
|
+
value?: T;
|
|
959
|
+
/**
|
|
960
|
+
* The default value.
|
|
961
|
+
*/
|
|
962
|
+
defaultValue?: T;
|
|
963
|
+
}>;
|
|
812
964
|
/**
|
|
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)
|
|
965
|
+
* A hook to manage a value.
|
|
819
966
|
*
|
|
820
967
|
* @example
|
|
821
968
|
*
|
|
822
|
-
* ```
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
* formatBytes(1024 * 1024) // 1 MB
|
|
969
|
+
* ```tsx
|
|
970
|
+
* const MyComponent = ({ value }: { value?: number }) => {
|
|
971
|
+
* const [currentValue, setCurrentValue] = useValue({ value });
|
|
972
|
+
* };
|
|
827
973
|
* ```
|
|
828
974
|
*/
|
|
829
|
-
declare const
|
|
975
|
+
declare const useValue: <T>({ value, defaultValue }: TValueOptions<T>) => readonly [T, (newValue: T) => void];
|
|
976
|
+
|
|
977
|
+
declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>): React.RefCallback<T>;
|
|
830
978
|
|
|
831
979
|
/**
|
|
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
|
-
*
|
|
980
|
+
* 民國年轉西元年
|
|
981
|
+
* @param dateString 日期字串
|
|
982
|
+
* @param format 日期格式
|
|
852
983
|
* @example
|
|
853
984
|
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
* validTaxId('00000000') // false
|
|
857
|
-
* validTaxId('11111111') // false
|
|
858
|
-
* validTaxId('22099132') // false
|
|
985
|
+
* rocEraToAd('1100201') // 20210201
|
|
986
|
+
* rocEraToAd('11002', 'YYYYMM') // 202102
|
|
859
987
|
*/
|
|
860
|
-
declare const
|
|
988
|
+
declare const rocEraToAd: (dateString: string, format?: string) => string;
|
|
861
989
|
/**
|
|
862
|
-
*
|
|
863
|
-
*
|
|
990
|
+
* 西元年轉民國年
|
|
864
991
|
* @param dateString 日期字串
|
|
865
992
|
* @param format 日期格式
|
|
866
993
|
* @example
|
|
867
994
|
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* validateDateString('20210201', 'YYYY-MM-DD') // false
|
|
871
|
-
* validateDateString('20210201', 'YYYYMM') // false
|
|
995
|
+
* adToRocEra('20210201') // 1100201
|
|
996
|
+
* adToRocEra('202102', 'YYYYMM') // 11002
|
|
872
997
|
*/
|
|
873
|
-
declare const
|
|
998
|
+
declare const adToRocEra: (dateString: string, format?: string) => string;
|
|
874
999
|
|
|
875
1000
|
/**
|
|
876
|
-
*
|
|
877
|
-
*
|
|
1001
|
+
* 取得去年今年以及明年期別陣列
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* // 假設 今年為 112 年
|
|
1005
|
+
* generatePeriodArray() // 11102 ~ 11312
|
|
878
1006
|
*/
|
|
879
|
-
declare const
|
|
1007
|
+
declare const generatePeriodArray: () => string[];
|
|
1008
|
+
/**
|
|
1009
|
+
* 取得當前期別
|
|
1010
|
+
*
|
|
1011
|
+
* 報稅期限次期開始15日內
|
|
1012
|
+
*
|
|
1013
|
+
* 雙數月沒有特殊規則,期別皆為當月開頭
|
|
1014
|
+
*
|
|
1015
|
+
* 單數月15號以前,期別為上個月否則為下個月開頭
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
*
|
|
1019
|
+
* // 假設今天是 111-02-15
|
|
1020
|
+
* getCurrentPeriod() // 11102
|
|
1021
|
+
* // 假設今天是 111-02-16
|
|
1022
|
+
* getCurrentPeriod() // 11102
|
|
1023
|
+
* // 假設今天是 111-03-15
|
|
1024
|
+
* getCurrentPeriod() // 11102
|
|
1025
|
+
* // 假設今天是 111-03-16
|
|
1026
|
+
* getCurrentPeriod() // 11104
|
|
1027
|
+
*/
|
|
1028
|
+
declare const getCurrentPeriod: () => string;
|
|
880
1029
|
|
|
881
1030
|
/**
|
|
882
1031
|
* Downloads a file from a given source.
|
|
@@ -911,5 +1060,4 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
911
1060
|
*/
|
|
912
1061
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
913
1062
|
|
|
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 };
|
|
1063
|
+
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, 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 };
|