@gateweb/react-utils 0.0.2 → 0.0.3
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 +25 -20
- package/dist/cjs/index.js +0 -22
- package/dist/es/index.d.mts +25 -20
- package/dist/es/index.mjs +1 -22
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -292,25 +292,6 @@ declare const omit: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
|
|
|
292
292
|
* const b = omitByValue(a, undefined, null); // { c: 3, d: 4 }
|
|
293
293
|
*/
|
|
294
294
|
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
295
|
|
|
315
296
|
/**
|
|
316
297
|
* debounce function
|
|
@@ -619,4 +600,28 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
619
600
|
*/
|
|
620
601
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
621
602
|
|
|
622
|
-
|
|
603
|
+
/**
|
|
604
|
+
* 從對象類型中提取特定屬性的值類型。
|
|
605
|
+
*
|
|
606
|
+
* @template T 要處理的對象類型
|
|
607
|
+
* @template K 要提取的屬性名(字符串字面量類型)
|
|
608
|
+
*
|
|
609
|
+
* @description
|
|
610
|
+
* 這個類型用於從一個對象類型 T 中提取指定屬性 K 的值類型。
|
|
611
|
+
* T 應該是一個對象,其每個屬性都是另一個包含 K 屬性的對象。
|
|
612
|
+
* 如果 T 不符合這個結構,或者指定的屬性 K 不存在,則返回 never。
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* type Obj = {
|
|
616
|
+
* a: { value: string },
|
|
617
|
+
* b: { value: number }
|
|
618
|
+
* };
|
|
619
|
+
* type Result = ExtractValueType<Obj, 'value'>; // string | number
|
|
620
|
+
*
|
|
621
|
+
* @returns 返回 T 中所有 K 屬性值的聯合類型,如果不符合條件則返回 never
|
|
622
|
+
*/
|
|
623
|
+
type TExtractValueType<T, K extends string> = T extends Record<string, {
|
|
624
|
+
[P in K]: infer R;
|
|
625
|
+
}> ? R : never;
|
|
626
|
+
|
|
627
|
+
export { type TCountdownActions, type TExtractValueType, 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;
|
package/dist/es/index.d.mts
CHANGED
|
@@ -292,25 +292,6 @@ declare const omit: <T extends object, K extends [...(keyof T)[]]>(object: T, ..
|
|
|
292
292
|
* const b = omitByValue(a, undefined, null); // { c: 3, d: 4 }
|
|
293
293
|
*/
|
|
294
294
|
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
295
|
|
|
315
296
|
/**
|
|
316
297
|
* debounce function
|
|
@@ -619,4 +600,28 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
619
600
|
*/
|
|
620
601
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
621
602
|
|
|
622
|
-
|
|
603
|
+
/**
|
|
604
|
+
* 從對象類型中提取特定屬性的值類型。
|
|
605
|
+
*
|
|
606
|
+
* @template T 要處理的對象類型
|
|
607
|
+
* @template K 要提取的屬性名(字符串字面量類型)
|
|
608
|
+
*
|
|
609
|
+
* @description
|
|
610
|
+
* 這個類型用於從一個對象類型 T 中提取指定屬性 K 的值類型。
|
|
611
|
+
* T 應該是一個對象,其每個屬性都是另一個包含 K 屬性的對象。
|
|
612
|
+
* 如果 T 不符合這個結構,或者指定的屬性 K 不存在,則返回 never。
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* type Obj = {
|
|
616
|
+
* a: { value: string },
|
|
617
|
+
* b: { value: number }
|
|
618
|
+
* };
|
|
619
|
+
* type Result = ExtractValueType<Obj, 'value'>; // string | number
|
|
620
|
+
*
|
|
621
|
+
* @returns 返回 T 中所有 K 屬性值的聯合類型,如果不符合條件則返回 never
|
|
622
|
+
*/
|
|
623
|
+
type TExtractValueType<T, K extends string> = T extends Record<string, {
|
|
624
|
+
[P in K]: infer R;
|
|
625
|
+
}> ? R : never;
|
|
626
|
+
|
|
627
|
+
export { type TCountdownActions, type TExtractValueType, 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,
|
|
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 };
|