@gateweb/react-utils 0.0.2 → 0.0.4

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.
@@ -1,3 +1,5 @@
1
+ export * from './types.js';
2
+
1
3
  type CamelToPascal<S extends string> = S extends `${infer Head}${infer Tail}` ? `${Uppercase<Head>}${Tail}` : S;
2
4
  /**
3
5
  * convert CamelCase string to PascalCase string
@@ -292,25 +294,6 @@ declare const omit: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
292
294
  * const b = omitByValue(a, undefined, null); // { c: 3, d: 4 }
293
295
  */
294
296
  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]>;
295
- /**
296
- * 將指定格式的物件轉換成類似 enum 的物件
297
- *
298
- * @param enumObject enum 物件
299
- * @param valueKey value 的 key
300
- *
301
- * @example
302
- *
303
- * ```js
304
- * const myObj = {
305
- * A: { value: 'a' },
306
- * B: { value: 'b', other: 'other' },
307
- * }
308
- *
309
- * const enumCode = extractEnumLikeObject(myObj, 'value');
310
- * console.log(enumCode); // { A: 'a', B: 'b' }
311
- * ```
312
- */
313
- declare const extractEnumLikeObject: <T extends Record<string, { [P in K]: any; }>, K extends string>(enumObject: T, valueKey: K) => { [key in keyof T]: T[key][K]; };
314
297
 
315
298
  /**
316
299
  * debounce function
@@ -619,4 +602,4 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
619
602
  */
620
603
  declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
621
604
 
622
- export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, debounce, downloadFile, extractEnumLikeObject, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType };
605
+ export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, debounce, downloadFile, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType };
package/dist/cjs/index.js CHANGED
@@ -442,27 +442,6 @@ message) {
442
442
  [key]: value
443
443
  };
444
444
  }, {});
445
- /**
446
- * 將指定格式的物件轉換成類似 enum 的物件
447
- *
448
- * @param enumObject enum 物件
449
- * @param valueKey value 的 key
450
- *
451
- * @example
452
- *
453
- * ```js
454
- * const myObj = {
455
- * A: { value: 'a' },
456
- * B: { value: 'b', other: 'other' },
457
- * }
458
- *
459
- * const enumCode = extractEnumLikeObject(myObj, 'value');
460
- * console.log(enumCode); // { A: 'a', B: 'b' }
461
- * ```
462
- */ const extractEnumLikeObject = (enumObject, valueKey)=>Object.entries(enumObject).reduce((acc, [key, value])=>({
463
- ...acc,
464
- [key]: value[valueKey]
465
- }), {});
466
445
 
467
446
  /**
468
447
  * debounce function
@@ -705,7 +684,6 @@ exports.camelCase2SnakeCase = camelCase2SnakeCase;
705
684
  exports.camelString2PascalString = camelString2PascalString;
706
685
  exports.camelString2SnakeString = camelString2SnakeString;
707
686
  exports.debounce = debounce;
708
- exports.extractEnumLikeObject = extractEnumLikeObject;
709
687
  exports.formatAmount = formatAmount;
710
688
  exports.formatStarMask = formatStarMask;
711
689
  exports.generatePeriodArray = generatePeriodArray;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 從對象類型中提取特定屬性的值類型。
3
+ *
4
+ * @template T 要處理的對象類型
5
+ * @template K 要提取的屬性名(字符串字面量類型)
6
+ *
7
+ * @description
8
+ * 這個類型用於從一個對象類型 T 中提取指定屬性 K 的值類型。
9
+ * T 應該是一個對象,其每個屬性都是另一個包含 K 屬性的對象。
10
+ * 如果 T 不符合這個結構,或者指定的屬性 K 不存在,則返回 never。
11
+ *
12
+ * @example
13
+ * type Obj = {
14
+ * a: { value: string },
15
+ * b: { value: number }
16
+ * };
17
+ * type Result = ExtractValueType<Obj, 'value'>; // string | number
18
+ *
19
+ * @returns 返回 T 中所有 K 屬性值的聯合類型,如果不符合條件則返回 never
20
+ */
21
+ type TExtractValueType<T, K extends string> = T extends Record<string, {
22
+ [P in K]: infer R;
23
+ }> ? R : never;
24
+
25
+ export type { TExtractValueType };
@@ -0,0 +1 @@
1
+
@@ -1,3 +1,5 @@
1
+ export * from './types.mjs';
2
+
1
3
  type CamelToPascal<S extends string> = S extends `${infer Head}${infer Tail}` ? `${Uppercase<Head>}${Tail}` : S;
2
4
  /**
3
5
  * convert CamelCase string to PascalCase string
@@ -292,25 +294,6 @@ declare const omit: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
292
294
  * const b = omitByValue(a, undefined, null); // { c: 3, d: 4 }
293
295
  */
294
296
  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]>;
295
- /**
296
- * 將指定格式的物件轉換成類似 enum 的物件
297
- *
298
- * @param enumObject enum 物件
299
- * @param valueKey value 的 key
300
- *
301
- * @example
302
- *
303
- * ```js
304
- * const myObj = {
305
- * A: { value: 'a' },
306
- * B: { value: 'b', other: 'other' },
307
- * }
308
- *
309
- * const enumCode = extractEnumLikeObject(myObj, 'value');
310
- * console.log(enumCode); // { A: 'a', B: 'b' }
311
- * ```
312
- */
313
- declare const extractEnumLikeObject: <T extends Record<string, { [P in K]: any; }>, K extends string>(enumObject: T, valueKey: K) => { [key in keyof T]: T[key][K]; };
314
297
 
315
298
  /**
316
299
  * debounce function
@@ -619,4 +602,4 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
619
602
  */
620
603
  declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
621
604
 
622
- export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, debounce, downloadFile, extractEnumLikeObject, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType };
605
+ export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, debounce, downloadFile, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType };
package/dist/es/index.mjs CHANGED
@@ -436,27 +436,6 @@ message) {
436
436
  [key]: value
437
437
  };
438
438
  }, {});
439
- /**
440
- * 將指定格式的物件轉換成類似 enum 的物件
441
- *
442
- * @param enumObject enum 物件
443
- * @param valueKey value 的 key
444
- *
445
- * @example
446
- *
447
- * ```js
448
- * const myObj = {
449
- * A: { value: 'a' },
450
- * B: { value: 'b', other: 'other' },
451
- * }
452
- *
453
- * const enumCode = extractEnumLikeObject(myObj, 'value');
454
- * console.log(enumCode); // { A: 'a', B: 'b' }
455
- * ```
456
- */ const extractEnumLikeObject = (enumObject, valueKey)=>Object.entries(enumObject).reduce((acc, [key, value])=>({
457
- ...acc,
458
- [key]: value[valueKey]
459
- }), {});
460
439
 
461
440
  /**
462
441
  * debounce function
@@ -689,4 +668,4 @@ message) {
689
668
  * formatString('123456', 1, 4) // '1****6'
690
669
  */ const formatStarMask = (str, n, m)=>str.slice(0, n) + '*'.repeat(m - n + 1) + str.slice(m + 1);
691
670
 
692
- export { adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, debounce, extractEnumLikeObject, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, validTaxId, validateDateString, validateFileType };
671
+ export { adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, debounce, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, validTaxId, validateDateString, validateFileType };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 從對象類型中提取特定屬性的值類型。
3
+ *
4
+ * @template T 要處理的對象類型
5
+ * @template K 要提取的屬性名(字符串字面量類型)
6
+ *
7
+ * @description
8
+ * 這個類型用於從一個對象類型 T 中提取指定屬性 K 的值類型。
9
+ * T 應該是一個對象,其每個屬性都是另一個包含 K 屬性的對象。
10
+ * 如果 T 不符合這個結構,或者指定的屬性 K 不存在,則返回 never。
11
+ *
12
+ * @example
13
+ * type Obj = {
14
+ * a: { value: string },
15
+ * b: { value: number }
16
+ * };
17
+ * type Result = ExtractValueType<Obj, 'value'>; // string | number
18
+ *
19
+ * @returns 返回 T 中所有 K 屬性值的聯合類型,如果不符合條件則返回 never
20
+ */
21
+ type TExtractValueType<T, K extends string> = T extends Record<string, {
22
+ [P in K]: infer R;
23
+ }> ? R : never;
24
+
25
+ export type { TExtractValueType };
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gateweb/react-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "React Utils for GateWeb",
5
5
  "homepage": "https://github.com/GatewebSolutions/react-utils",
6
6
  "files": [
@@ -19,6 +19,16 @@
19
19
  "types": "./dist/cjs/index.d.ts",
20
20
  "default": "./dist/cjs/index.js"
21
21
  }
22
+ },
23
+ "./types": {
24
+ "import": {
25
+ "types": "./dist/es/types.d.mts",
26
+ "default": "./dist/es/types.mjs"
27
+ },
28
+ "require": {
29
+ "types": "./dist/cjs/types.d.ts",
30
+ "default": "./dist/cjs/types.js"
31
+ }
22
32
  }
23
33
  },
24
34
  "publishConfig": {