@gateweb/react-utils 1.6.0 → 1.7.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 +36 -1
- package/dist/cjs/types.d.ts +17 -1
- package/dist/es/index.d.mts +36 -1
- package/dist/es/types.d.mts +17 -1
- package/package.json +4 -2
package/dist/cjs/index.d.ts
CHANGED
|
@@ -438,6 +438,40 @@ declare const pickByValue: <T extends object, K extends any[]>(object: T, ...val
|
|
|
438
438
|
*
|
|
439
439
|
*/
|
|
440
440
|
declare const deepMerge: <T extends object, U extends object>(target: T, source: U) => T & U;
|
|
441
|
+
/**
|
|
442
|
+
* a utility type to make all properties of an object required
|
|
443
|
+
*
|
|
444
|
+
* @param T - the object type
|
|
445
|
+
* @param K - the keys to make required
|
|
446
|
+
* @param RemoveUndefined - whether to remove undefined from the type
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
*
|
|
450
|
+
* type A = { a?: number; b?: string | undefined; c?: boolean };
|
|
451
|
+
* // Even though b is required, it can be undefined
|
|
452
|
+
* type B = RequiredBy<A, 'a' | 'b'>; // { a: number; b: string | undefined; c?: boolean
|
|
453
|
+
* type C = RequiredBy<A, 'a' | 'b', true>; // { a: number; b: string; c?: boolean }
|
|
454
|
+
*/
|
|
455
|
+
type RequiredBy<T, K extends keyof T, RemoveUndefined extends boolean = false> = Omit<T, K> & {
|
|
456
|
+
[P in K]-?: RemoveUndefined extends true ? Exclude<T[P], undefined> : T[P];
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* a utility type to make all properties of an object optional
|
|
460
|
+
*
|
|
461
|
+
* @param T - the object type
|
|
462
|
+
* @param K - the keys to make optional
|
|
463
|
+
* @param RemoveUndefined - whether to remove undefined from the type
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
*
|
|
467
|
+
* type A = { a: number; b: string | undefined; c: boolean };
|
|
468
|
+
* // Even though b is optional, it can be undefined
|
|
469
|
+
* type B = PartialBy<A, 'a' | 'b'>; // { a?: number; b?: string | undefined; c: boolean }
|
|
470
|
+
* type C = PartialBy<A, 'a' | 'b', true>; // { a?: number; b?: string; c: boolean }
|
|
471
|
+
*/
|
|
472
|
+
type PartialBy<T, K extends keyof T, RemoveUndefined extends boolean = false> = Omit<T, K> & {
|
|
473
|
+
[P in K]?: RemoveUndefined extends true ? Exclude<T[P], undefined> : T[P];
|
|
474
|
+
};
|
|
441
475
|
|
|
442
476
|
/**
|
|
443
477
|
* debounce function
|
|
@@ -827,4 +861,5 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
827
861
|
*/
|
|
828
862
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
829
863
|
|
|
830
|
-
export {
|
|
864
|
+
export { 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, useValue, validTaxId, validateDateString, validateFileType, wait };
|
|
865
|
+
export type { PartialBy, RequiredBy, TCountdownActions };
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -88,6 +88,8 @@ type Entries<T> = {
|
|
|
88
88
|
*
|
|
89
89
|
* @template T - The object type to transform into keys.
|
|
90
90
|
*
|
|
91
|
+
* @deprecated Use `MapToType` instead.
|
|
92
|
+
*
|
|
91
93
|
* @example
|
|
92
94
|
*
|
|
93
95
|
* type Example = { a: number; b: string };
|
|
@@ -171,5 +173,19 @@ type DeepPartial<T> = (T extends (infer U)[] ? DeepPartial<U>[] : {
|
|
|
171
173
|
type TChangeKeyType<T, K extends keyof T, V> = Omit<T, K> & {
|
|
172
174
|
[P in K]: V;
|
|
173
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* A utility type that transforms an object type `T` into another object type where each value type is replaced with type `A`.
|
|
178
|
+
*
|
|
179
|
+
* @template T - The object type to transform into keys.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
*
|
|
183
|
+
* type Example = { a: number; b: string };
|
|
184
|
+
* type ExampleToBoolean = MapToType<Example, boolean>;
|
|
185
|
+
* // Result: ExampleToBoolean is { a: boolean; b: boolean; }
|
|
186
|
+
*/
|
|
187
|
+
type MapToType<T extends Record<any, any>, A = any> = {
|
|
188
|
+
[K in keyof T]: A;
|
|
189
|
+
};
|
|
174
190
|
|
|
175
|
-
export type { AtLeastOne, DeepPartial, Entries, MapToString, OnlyOne, PopArgs, PushArgs, ShiftArgs, TChangeKeyType, TExtractValueType, UnshiftArgs };
|
|
191
|
+
export type { AtLeastOne, DeepPartial, Entries, MapToString, MapToType, OnlyOne, PopArgs, PushArgs, ShiftArgs, TChangeKeyType, TExtractValueType, UnshiftArgs };
|
package/dist/es/index.d.mts
CHANGED
|
@@ -438,6 +438,40 @@ declare const pickByValue: <T extends object, K extends any[]>(object: T, ...val
|
|
|
438
438
|
*
|
|
439
439
|
*/
|
|
440
440
|
declare const deepMerge: <T extends object, U extends object>(target: T, source: U) => T & U;
|
|
441
|
+
/**
|
|
442
|
+
* a utility type to make all properties of an object required
|
|
443
|
+
*
|
|
444
|
+
* @param T - the object type
|
|
445
|
+
* @param K - the keys to make required
|
|
446
|
+
* @param RemoveUndefined - whether to remove undefined from the type
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
*
|
|
450
|
+
* type A = { a?: number; b?: string | undefined; c?: boolean };
|
|
451
|
+
* // Even though b is required, it can be undefined
|
|
452
|
+
* type B = RequiredBy<A, 'a' | 'b'>; // { a: number; b: string | undefined; c?: boolean
|
|
453
|
+
* type C = RequiredBy<A, 'a' | 'b', true>; // { a: number; b: string; c?: boolean }
|
|
454
|
+
*/
|
|
455
|
+
type RequiredBy<T, K extends keyof T, RemoveUndefined extends boolean = false> = Omit<T, K> & {
|
|
456
|
+
[P in K]-?: RemoveUndefined extends true ? Exclude<T[P], undefined> : T[P];
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* a utility type to make all properties of an object optional
|
|
460
|
+
*
|
|
461
|
+
* @param T - the object type
|
|
462
|
+
* @param K - the keys to make optional
|
|
463
|
+
* @param RemoveUndefined - whether to remove undefined from the type
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
*
|
|
467
|
+
* type A = { a: number; b: string | undefined; c: boolean };
|
|
468
|
+
* // Even though b is optional, it can be undefined
|
|
469
|
+
* type B = PartialBy<A, 'a' | 'b'>; // { a?: number; b?: string | undefined; c: boolean }
|
|
470
|
+
* type C = PartialBy<A, 'a' | 'b', true>; // { a?: number; b?: string; c: boolean }
|
|
471
|
+
*/
|
|
472
|
+
type PartialBy<T, K extends keyof T, RemoveUndefined extends boolean = false> = Omit<T, K> & {
|
|
473
|
+
[P in K]?: RemoveUndefined extends true ? Exclude<T[P], undefined> : T[P];
|
|
474
|
+
};
|
|
441
475
|
|
|
442
476
|
/**
|
|
443
477
|
* debounce function
|
|
@@ -827,4 +861,5 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
827
861
|
*/
|
|
828
862
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
829
863
|
|
|
830
|
-
export {
|
|
864
|
+
export { 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, useValue, validTaxId, validateDateString, validateFileType, wait };
|
|
865
|
+
export type { PartialBy, RequiredBy, TCountdownActions };
|
package/dist/es/types.d.mts
CHANGED
|
@@ -88,6 +88,8 @@ type Entries<T> = {
|
|
|
88
88
|
*
|
|
89
89
|
* @template T - The object type to transform into keys.
|
|
90
90
|
*
|
|
91
|
+
* @deprecated Use `MapToType` instead.
|
|
92
|
+
*
|
|
91
93
|
* @example
|
|
92
94
|
*
|
|
93
95
|
* type Example = { a: number; b: string };
|
|
@@ -171,5 +173,19 @@ type DeepPartial<T> = (T extends (infer U)[] ? DeepPartial<U>[] : {
|
|
|
171
173
|
type TChangeKeyType<T, K extends keyof T, V> = Omit<T, K> & {
|
|
172
174
|
[P in K]: V;
|
|
173
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* A utility type that transforms an object type `T` into another object type where each value type is replaced with type `A`.
|
|
178
|
+
*
|
|
179
|
+
* @template T - The object type to transform into keys.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
*
|
|
183
|
+
* type Example = { a: number; b: string };
|
|
184
|
+
* type ExampleToBoolean = MapToType<Example, boolean>;
|
|
185
|
+
* // Result: ExampleToBoolean is { a: boolean; b: boolean; }
|
|
186
|
+
*/
|
|
187
|
+
type MapToType<T extends Record<any, any>, A = any> = {
|
|
188
|
+
[K in keyof T]: A;
|
|
189
|
+
};
|
|
174
190
|
|
|
175
|
-
export type { AtLeastOne, DeepPartial, Entries, MapToString, OnlyOne, PopArgs, PushArgs, ShiftArgs, TChangeKeyType, TExtractValueType, UnshiftArgs };
|
|
191
|
+
export type { AtLeastOne, DeepPartial, Entries, MapToString, MapToType, OnlyOne, PopArgs, PushArgs, ShiftArgs, TChangeKeyType, TExtractValueType, UnshiftArgs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gateweb/react-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "React Utils for GateWeb",
|
|
5
5
|
"homepage": "https://github.com/GatewebSolutions/react-utils",
|
|
6
6
|
"files": [
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"dayjs": "^1.11.13",
|
|
39
39
|
"react": "^19.0.0",
|
|
40
|
-
"react-dom": "^19.0.0"
|
|
40
|
+
"react-dom": "^19.0.0",
|
|
41
|
+
"use-sync-external-store": "^1.5.0",
|
|
42
|
+
"zustand": "^5.0.3"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@commitlint/cli": "^19.5.0",
|