@adaskothebeast/hierarchical-convert-to-date 2.0.0 → 3.0.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/README.md
CHANGED
|
@@ -337,33 +337,18 @@ This will initiate the fetch when your component mounts and dispatch either a su
|
|
|
337
337
|
|
|
338
338
|
Please adjust the code according to your requirements and project structure.
|
|
339
339
|
|
|
340
|
-
### Axios
|
|
340
|
+
### Axios with AxiosInstanceManager
|
|
341
341
|
|
|
342
|
-
|
|
342
|
+
The AxiosInstanceManager class simplifies the process of using Axios with the `hierarchicalConvertToDate` function. By utilizing this class, you can easily create and use a centralized Axios instance with a response interceptor that automatically processes response data.
|
|
343
343
|
|
|
344
|
-
Here
|
|
344
|
+
Here's how to use AxiosInstanceManager:
|
|
345
345
|
|
|
346
346
|
```ts
|
|
347
|
-
import
|
|
348
|
-
|
|
349
|
-
// Adjust this import as needed - this will import adjustment function for pure js Date object
|
|
347
|
+
import { AxiosInstanceManager } from '@adaskothebeast/axios-interceptor';
|
|
350
348
|
import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
|
|
351
349
|
|
|
352
|
-
// Create an instance
|
|
353
|
-
const instance =
|
|
354
|
-
|
|
355
|
-
// Add a response interceptor
|
|
356
|
-
instance.interceptors.response.use((response) => {
|
|
357
|
-
// Any status code that lies within the range of 2xx cause this function to trigger
|
|
358
|
-
// Parse the dates in the response data
|
|
359
|
-
hierarchicalConvertToDate(response.data);
|
|
360
|
-
// Then return the response object
|
|
361
|
-
return response;
|
|
362
|
-
}, (error) => {
|
|
363
|
-
// Any status codes that falls outside the range of 2xx cause this function to trigger
|
|
364
|
-
// You can handle the error here
|
|
365
|
-
return Promise.reject(error);
|
|
366
|
-
});
|
|
350
|
+
// Create an Axios instance using AxiosInstanceManager
|
|
351
|
+
const instance = AxiosInstanceManager.createInstance(hierarchicalConvertToDate);
|
|
367
352
|
|
|
368
353
|
async function fetchApiData() {
|
|
369
354
|
try {
|
|
@@ -377,8 +362,9 @@ async function fetchApiData() {
|
|
|
377
362
|
fetchApiData();
|
|
378
363
|
```
|
|
379
364
|
|
|
380
|
-
In the code above
|
|
365
|
+
In the code above:
|
|
381
366
|
|
|
382
|
-
The
|
|
367
|
+
- The createInstance method of AxiosInstanceManager is used to create and configure an Axios instance. This instance is configured with a response interceptor that applies hierarchicalConvertToDate to response.data. This conversion function processes any date strings in the response data into JavaScript Date objects (or in case of other libs proper class for given date lib).
|
|
368
|
+
- The fetchApiData function demonstrates using the configured Axios instance to make a GET request. The response data, with date strings already converted into Date (or in case of other libs proper class for given date lib) objects, is logged to the console. Errors from the request are caught and logged.
|
|
383
369
|
|
|
384
|
-
|
|
370
|
+
This approach encapsulates the Axios configuration, making your code cleaner and more maintainable. Remember to adjust imports and function calls as per your project's file structure and requirements.
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaskothebeast/hierarchical-convert-to-date",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Adam Pluciński <adaskothebeast@gmail.com> (https://github.com/adaskothebeast)",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/AdaskoTheBeAsT/date-interceptors.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/AdaskoTheBeAsT/date-interceptors/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/AdaskoTheBeAsT/date-interceptors",
|
|
4
14
|
"peerDependencies": {
|
|
5
15
|
"tslib": "^2.6.2"
|
|
6
16
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hierarchicalConvertToDate = void 0;
|
|
4
4
|
// Regular expression that matches ISO 8601 date strings
|
|
5
|
-
const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z
|
|
5
|
+
const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|([+-]\d{2}:\d{2}))?$/;
|
|
6
6
|
/**
|
|
7
7
|
* Function to recursively traverse the object and convert date strings to Date objects in place.
|
|
8
8
|
* @param obj Object to traverse
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hierarchical-convert-to-date.js","sourceRoot":"","sources":["../../../../../libs/hierarchical-convert-to-date/src/lib/hierarchical-convert-to-date.ts"],"names":[],"mappings":";;;AAEA,wDAAwD;AACxD,MAAM,SAAS,GAAW,
|
|
1
|
+
{"version":3,"file":"hierarchical-convert-to-date.js","sourceRoot":"","sources":["../../../../../libs/hierarchical-convert-to-date/src/lib/hierarchical-convert-to-date.ts"],"names":[],"mappings":";;;AAEA,wDAAwD;AACxD,MAAM,SAAS,GAAW,uEAAuE,CAAC;AAElG;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,GAAY;IACpD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO;KACR;IACD,MAAM,CAAC,GAAG,GAAqB,CAAC;IAEhC,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;QACnB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;YACjD,SAAS;SACV;QAED,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACjB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC9C,6DAA6D;YAC7D,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;SACtB;aAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAChC,6EAA6E;YAC7E,yBAAyB,CAAC,CAAC,CAAC,CAAC;SAC9B;KACF;AACH,CAAC;AApBD,8DAoBC"}
|