@adaskothebeast/react-redux-toolkit-hierarchical-date-hook 1.1.0 → 1.2.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/index.esm.d.ts +1 -0
- package/index.esm.js +51 -0
- package/package.json +6 -6
- package/index.js +0 -1587
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src\\index";
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import 'core-js/modules/es.array.iterator.js';
|
|
2
|
+
import 'core-js/modules/es.object.assign.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This custom hook transforms the string date fields based on matching regex to Date objects
|
|
6
|
+
* of a Redux Toolkit query result using the HierarchicalConverter.
|
|
7
|
+
* In cases of some libraries it is also possible to convert Period automatically.
|
|
8
|
+
* It deep-clones the data field and then performs the conversion.
|
|
9
|
+
* If there's no data, it returns the original query result unchanged.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```jsx
|
|
13
|
+
* // choose one function from below depending on library which you use for date manipulation
|
|
14
|
+
* import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
|
|
15
|
+
* import { hierarchicalConvertToDateFns } from '@adaskothebeast/hierarchical-convert-to-date-fns';
|
|
16
|
+
* import { hierarchicalConvertToDayjs } from '@adaskothebeast/hierarchical-convert-to-dayjs';
|
|
17
|
+
* import { hierarchicalConvertToJsJoda } from '@adaskothebeast/hierarchical-convert-to-js-joda';
|
|
18
|
+
* import { hierarchicalConvertToLuxon } from '@adaskothebeast/hierarchical-convert-to-luxon';
|
|
19
|
+
* import { hierarchicalConvertToMoment } from '@adaskothebeast/hierarchical-convert-to-moment';
|
|
20
|
+
*
|
|
21
|
+
* const MyComponent: React.FC = () => {
|
|
22
|
+
* // Call your generated hook here
|
|
23
|
+
* const useQueryResult = useQueryFunction(arg, options);
|
|
24
|
+
*
|
|
25
|
+
* // Pass the result to the custom hook
|
|
26
|
+
* const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, hierarchicalConvertToDate);
|
|
27
|
+
*
|
|
28
|
+
* // Rest of your component...
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param useQueryResult The result of a Redux Toolkit query hook
|
|
33
|
+
* @param convertFunc The function that performs the conversion in place
|
|
34
|
+
* @returns The original query result with its data field transformed, if it exists
|
|
35
|
+
*/
|
|
36
|
+
function useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, convertFunc) {
|
|
37
|
+
const result = useQueryResult;
|
|
38
|
+
// Transform 'data' field if it exists
|
|
39
|
+
if (result.data) {
|
|
40
|
+
// Deep clone the data to avoid mutating the state directly
|
|
41
|
+
const clonedData = structuredClone(result.data);
|
|
42
|
+
convertFunc(clonedData);
|
|
43
|
+
return Object.assign(Object.assign({}, result), {
|
|
44
|
+
data: clonedData
|
|
45
|
+
}); // Type assertion via 'unknown'
|
|
46
|
+
}
|
|
47
|
+
// If there's no 'data', return the result as is
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { useAdjustUseQueryHookResultWithHierarchicalDateConverter };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaskothebeast/react-redux-toolkit-hierarchical-date-hook",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@reduxjs/toolkit": "^1.9.5"
|
|
5
|
+
"@reduxjs/toolkit": "^1.9.5",
|
|
6
|
+
"core-js": "3.32.0"
|
|
6
7
|
},
|
|
7
8
|
"devDependencies": {
|
|
8
|
-
"@adaskothebeast/hierarchical-convert-to-date": "1.
|
|
9
|
+
"@adaskothebeast/hierarchical-convert-to-date": "1.2.0"
|
|
9
10
|
},
|
|
10
11
|
"sideEffects": false,
|
|
11
|
-
"module": "./index.js",
|
|
12
|
-
"main": "./index.js",
|
|
12
|
+
"module": "./index.esm.js",
|
|
13
13
|
"type": "module",
|
|
14
|
-
"
|
|
14
|
+
"main": "./index.esm.js"
|
|
15
15
|
}
|