@gateweb/react-utils 1.15.0 → 1.17.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.
@@ -2,6 +2,74 @@ import React, { ReactNode } from 'react';
2
2
  import { AtLeastOne } from './types.mjs';
3
3
  export * from './types.mjs';
4
4
 
5
+ /**
6
+ * 將位元組陣列編碼為 base64 字串
7
+ *
8
+ * @param bytes 要編碼的位元組陣列
9
+ * @returns base64 編碼的字串
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const bytes = new TextEncoder().encode('Hello World');
14
+ * const encoded = encodeBase64(bytes);
15
+ * console.log(encoded); // 'SGVsbG8gV29ybGQ='
16
+ * ```
17
+ */
18
+ declare const encodeBase64: (bytes: Uint8Array) => string;
19
+ /**
20
+ * 將 base64 字串解碼為位元組陣列
21
+ *
22
+ * @param base64 要解碼的 base64 字串(支援 base64url 格式)
23
+ * @returns 解碼後的位元組陣列
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const decoded = decodeBase64('SGVsbG8gV29ybGQ=');
28
+ * const text = new TextDecoder().decode(decoded);
29
+ * console.log(text); // 'Hello World'
30
+ * ```
31
+ */
32
+ declare const decodeBase64: (base64: string) => Uint8Array;
33
+ /**
34
+ * JSON 可序列化的資料類型
35
+ */
36
+ type JsonSerializable = string | number | boolean | null | JsonSerializable[] | {
37
+ [key: string]: JsonSerializable;
38
+ };
39
+ /**
40
+ * 將 JSON 資料編碼為 base64 字串
41
+ *
42
+ * @param data 要編碼的 JSON 可序列化資料
43
+ * @returns base64 編碼的字串
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const data = { name: 'John', age: 30 };
48
+ * const encoded = encodeJson(data);
49
+ * console.log(encoded); // 'eyJuYW1lIjoiSm9obiIsImFnZSI6MzB9'
50
+ *
51
+ * const array = [1, 2, 3];
52
+ * const encodedArray = encodeJson(array);
53
+ * ```
54
+ */
55
+ declare const encodeJson: <T extends JsonSerializable>(data: T) => string;
56
+ /**
57
+ * 將 base64 字串解碼為 JSON 資料
58
+ *
59
+ * @param b64 要解碼的 base64 字串
60
+ * @returns 解碼後的資料
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const encoded = 'eyJuYW1lIjoiSm9obiIsImFnZSI6MzB9';
65
+ * const decoded = decodeJson<{ name: string; age: number }>(encoded);
66
+ * console.log(decoded); // { name: 'John', age: 30 }
67
+ *
68
+ * const decodedArray = decodeJson<number[]>(encodedArray);
69
+ * ```
70
+ */
71
+ declare const decodeJson: <T extends JsonSerializable>(b64: string) => T;
72
+
5
73
  declare const FILE_SIZE_UNITS: readonly ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
6
74
  type FileSizeUnit = (typeof FILE_SIZE_UNITS)[number];
7
75
  /**
@@ -1226,6 +1294,26 @@ type TCountdownActions = {
1226
1294
  */
1227
1295
  declare const useCountdown: (initialCountdown: number, enableReinitialize?: boolean) => TCountdownActions;
1228
1296
 
1297
+ type UseDisclosureReturn = {
1298
+ /** Whether the disclosure is currently open. */
1299
+ isOpen: boolean;
1300
+ /** Open the disclosure (sets isOpen = true). */
1301
+ open: () => void;
1302
+ /** Close the disclosure (sets isOpen = false). */
1303
+ close: () => void;
1304
+ /** Toggle the disclosure state (open -> close or close -> open). */
1305
+ toggle: () => void;
1306
+ };
1307
+ /**
1308
+ * A small hook to control open/close state.
1309
+ *
1310
+ * Supports an optional controlled pattern by passing `isOpen` and `onChange`.
1311
+ *
1312
+ * @example
1313
+ * const { isOpen, open, close, toggle } = useDisclosure();
1314
+ */
1315
+ declare function useDisclosure(initialState?: boolean): UseDisclosureReturn;
1316
+
1229
1317
  type TValueOptions<T> = AtLeastOne<{
1230
1318
  /**
1231
1319
  * The controlled value.
@@ -1316,7 +1404,7 @@ declare const getCurrentPeriod: () => string;
1316
1404
  declare const downloadFile: (source: string | Blob, filename?: string, fileExtension?: string) => void;
1317
1405
 
1318
1406
  /**
1319
- * 從 localStorage 取得資料,支援槽狀取值
1407
+ * 從 localStorage 取得資料,支援槽狀取值(Json 物件)
1320
1408
  *
1321
1409
  * @param key 鍵值
1322
1410
  * @param deCode 是否解碼
@@ -1328,12 +1416,12 @@ declare const downloadFile: (source: string | Blob, filename?: string, fileExten
1328
1416
  */
1329
1417
  declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefined;
1330
1418
  /**
1331
- * 將資料存入 localStorage
1419
+ * 將資料(Json 物件)存入 localStorage
1332
1420
  * @param key 鍵值
1333
1421
  * @param value 可序列化的資料
1334
1422
  * @param enCode 是否編碼
1335
1423
  */
1336
1424
  declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
1337
1425
 
1338
- export { ByteSize, MimeTypeMap, OtherMimeType, QueryProvider, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, convertBytes, createDataContext, createEnumLikeObject, debounce, deepClone, deepMerge, downloadFile, extractEnumLikeObject, fakeApi, formatAmount, formatBytes, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isEqual, isNil, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, isValidPassword, maskString, mergeConfig, mergeRefs, objectToSearchParams, omit, omitByValue, parseFileInfoFromFilename, parseFilenameFromDisposition, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, pick, pickByValue, renameKey, rocEraToAd, searchParamsToObject, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, useQueryContext, useValue, validTaxId, validateDateString, validateFileType, wait };
1339
- export type { MimeTypeExtension, MimeTypeValue, PartialBy, RequiredBy, TCountdownActions };
1426
+ export { ByteSize, MimeTypeMap, OtherMimeType, QueryProvider, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, convertBytes, createDataContext, createEnumLikeObject, debounce, decodeBase64, decodeJson, deepClone, deepMerge, downloadFile, encodeBase64, encodeJson, extractEnumLikeObject, fakeApi, formatAmount, formatBytes, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isEqual, isNil, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, isValidPassword, maskString, mergeConfig, mergeRefs, objectToSearchParams, omit, omitByValue, parseFileInfoFromFilename, parseFilenameFromDisposition, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, pick, pickByValue, renameKey, rocEraToAd, searchParamsToObject, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, useDisclosure, useQueryContext, useValue, validTaxId, validateDateString, validateFileType, wait };
1427
+ export type { MimeTypeExtension, MimeTypeValue, PartialBy, RequiredBy, TCountdownActions, UseDisclosureReturn };