datatable-axios 0.0.6 → 0.0.8
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 +120 -1
- package/dist/datatable-axios.cjs.js +48 -17
- package/dist/datatable-axios.esm.js +48 -17
- package/dist/datatable-axios.umd.js +48 -17
- package/package.json +6 -3
package/Readme.md
CHANGED
|
@@ -1 +1,120 @@
|
|
|
1
|
-
# Datatable Axios
|
|
1
|
+
# Datatable Axios
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Datatable Axios is a simple and convenient npm package that helps you make GET, POST, and PUT requests with ease, while handling search parameters and pagination seamlessly. It's built on top of the popular Axios library, making it reliable and efficient for your data fetching needs.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Installation
|
|
8
|
+
You can install Datatable Axios using npm:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install datatable-axios
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
# Usage
|
|
15
|
+
To get started with Datatable Axios, follow these simple steps:
|
|
16
|
+
|
|
17
|
+
- use global axios plugin setup in `axios.js` (optional)
|
|
18
|
+
``` js
|
|
19
|
+
import axios from "axios"
|
|
20
|
+
|
|
21
|
+
// Make the axios library globally available on the window object
|
|
22
|
+
window.axios = axios
|
|
23
|
+
// Set your base API URL for seamless requests
|
|
24
|
+
window.axios.defaults.baseURL = "http://example.com/api/v1/"
|
|
25
|
+
|
|
26
|
+
// Other configuration here
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- Import the package at the top of your JavaScript file:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import datatable from 'datatable-axios'
|
|
33
|
+
```
|
|
34
|
+
- Initialize an instance of the Datatable class:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const datatable = new Datatable();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# Use of API URL:
|
|
41
|
+
|
|
42
|
+
- When you have a global `axios.js` configuration setting your baseURL, simplify your API calls by using just the path:
|
|
43
|
+
```js
|
|
44
|
+
const response = await datatable.get('products');
|
|
45
|
+
console.log(response.data);
|
|
46
|
+
```
|
|
47
|
+
- If you're not utilizing a global `axios.js` configuration for your baseURL, include the full URL when making API calls:
|
|
48
|
+
```js
|
|
49
|
+
const response = await datatable.get('url or path');
|
|
50
|
+
console.log(response.data);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# Use of HTTP requests:
|
|
54
|
+
|
|
55
|
+
- Perform a GET request:
|
|
56
|
+
```js
|
|
57
|
+
const response = await datatable.get('url or path');
|
|
58
|
+
console.log(response.data); // Display the fetched data
|
|
59
|
+
```
|
|
60
|
+
- Perform a POST request:
|
|
61
|
+
```js
|
|
62
|
+
const response = await datatable.post('url or path');
|
|
63
|
+
console.log(response.data); // Display the response data
|
|
64
|
+
```
|
|
65
|
+
- Perform a PUT request:
|
|
66
|
+
```js
|
|
67
|
+
const response = await datatable.put('url or path');
|
|
68
|
+
console.log(response.data); // Display the updated data
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
# Example of HTTP call:
|
|
72
|
+
- Example 1 :
|
|
73
|
+
```js
|
|
74
|
+
datatable.get('http://example.com/api/v1/products')
|
|
75
|
+
.then(response => {
|
|
76
|
+
console.log("Data fetched successfully:", response.data);
|
|
77
|
+
})
|
|
78
|
+
.catch(error => {
|
|
79
|
+
console.error("An error occurred:", error);
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
- Example 2 :
|
|
83
|
+
```js
|
|
84
|
+
try {
|
|
85
|
+
const response = await datatable.get('/api/v1/products');
|
|
86
|
+
console.log("Data fetched successfully:", response.data);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error("An error occurred:", error);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
<!-- # Advanced Usage
|
|
92
|
+
You can also pass search parameters, pagination, and search queries to your requests:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
// Append search parameters to the URL
|
|
96
|
+
const response = await datatable.get('https://api.example.com/data', {
|
|
97
|
+
page: 1,
|
|
98
|
+
paginate: 10,
|
|
99
|
+
search: 'keyword',
|
|
100
|
+
});
|
|
101
|
+
console.log(response.data);
|
|
102
|
+
|
|
103
|
+
// Similar usage for POST and PUT requests
|
|
104
|
+
|
|
105
|
+
``` -->
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# Contributing
|
|
109
|
+
We welcome contributions to enhance Datatable Axios! Feel free to open issues for bug reports or feature requests. If you'd like to contribute code, please fork the repository, make your changes, and submit a pull request.
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# License
|
|
113
|
+
Datatable Axios is released under the [MIT License](https://opensource.org/license/mit/).
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
Feel free to reach out to me at [<svg xmlns="http://www.w3.org/2000/svg" width="24" height="18.1" viewBox="0 0 256 193"><path fill="#4285F4" d="M58.182 192.05V93.14L27.507 65.077L0 49.504v125.091c0 9.658 7.825 17.455 17.455 17.455h40.727Z"/><path fill="#34A853" d="M197.818 192.05h40.727c9.659 0 17.455-7.826 17.455-17.455V49.505l-31.156 17.837l-27.026 25.798v98.91Z"/><path fill="#EA4335" d="m58.182 93.14l-4.174-38.647l4.174-36.989L128 69.868l69.818-52.364l4.669 34.992l-4.669 40.644L128 145.504z"/><path fill="#FBBC04" d="M197.818 17.504V93.14L256 49.504V26.231c0-21.585-24.64-33.89-41.89-20.945l-16.292 12.218Z"/><path fill="#C5221F" d="m0 49.504l26.759 20.07L58.182 93.14V17.504L41.89 5.286C24.61-7.66 0 4.646 0 26.23v23.273Z"/></svg>](mailto:mahmudunnabikajal@gmail.com)
|
|
118
|
+
[<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 128 128"><g fill="#fff"><path fill-rule="evenodd" d="M64 5.103c-33.347 0-60.388 27.035-60.388 60.388c0 26.682 17.303 49.317 41.297 57.303c3.017.56 4.125-1.31 4.125-2.905c0-1.44-.056-6.197-.082-11.243c-16.8 3.653-20.345-7.125-20.345-7.125c-2.747-6.98-6.705-8.836-6.705-8.836c-5.48-3.748.413-3.67.413-3.67c6.063.425 9.257 6.223 9.257 6.223c5.386 9.23 14.127 6.562 17.573 5.02c.542-3.903 2.107-6.568 3.834-8.076c-13.413-1.525-27.514-6.704-27.514-29.843c0-6.593 2.36-11.98 6.223-16.21c-.628-1.52-2.695-7.662.584-15.98c0 0 5.07-1.623 16.61 6.19C53.7 35 58.867 34.327 64 34.304c5.13.023 10.3.694 15.127 2.033c11.526-7.813 16.59-6.19 16.59-6.19c3.287 8.317 1.22 14.46.593 15.98c3.872 4.23 6.215 9.617 6.215 16.21c0 23.194-14.127 28.3-27.574 29.796c2.167 1.874 4.097 5.55 4.097 11.183c0 8.08-.07 14.583-.07 16.572c0 1.607 1.088 3.49 4.148 2.897c23.98-7.994 41.263-30.622 41.263-57.294C124.388 32.14 97.35 5.104 64 5.104z" clip-rule="evenodd"/><path d="M26.484 91.806c-.133.3-.605.39-1.035.185c-.44-.196-.685-.605-.543-.906c.13-.31.603-.395 1.04-.188c.44.197.69.61.537.91zm2.446 2.729c-.287.267-.85.143-1.232-.28c-.396-.42-.47-.983-.177-1.254c.298-.266.844-.14 1.24.28c.394.426.472.984.17 1.255zm2.382 3.477c-.37.258-.976.017-1.35-.52c-.37-.538-.37-1.183.01-1.44c.373-.258.97-.025 1.35.507c.368.545.368 1.19-.01 1.452zm3.261 3.361c-.33.365-1.036.267-1.552-.23c-.527-.487-.674-1.18-.343-1.544c.336-.366 1.045-.264 1.564.23c.527.486.686 1.18.333 1.543zm4.5 1.951c-.147.473-.825.688-1.51.486c-.683-.207-1.13-.76-.99-1.238c.14-.477.823-.7 1.512-.485c.683.206 1.13.756.988 1.237zm4.943.361c.017.498-.563.91-1.28.92c-.723.017-1.308-.387-1.315-.877c0-.503.568-.91 1.29-.924c.717-.013 1.306.387 1.306.88zm4.598-.782c.086.485-.413.984-1.126 1.117c-.7.13-1.35-.172-1.44-.653c-.086-.498.422-.997 1.122-1.126c.714-.123 1.354.17 1.444.663zm0 0"/></g></svg>](https://github.com/mahmudunnabikajal)
|
|
119
|
+
[<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 128 128"><path fill="#0076b2" d="M116 3H12a8.91 8.91 0 0 0-9 8.8v104.42a8.91 8.91 0 0 0 9 8.78h104a8.93 8.93 0 0 0 9-8.81V11.77A8.93 8.93 0 0 0 116 3z"/><path fill="#fff" d="M21.06 48.73h18.11V107H21.06zm9.06-29a10.5 10.5 0 1 1-10.5 10.49a10.5 10.5 0 0 1 10.5-10.49m20.41 29h17.36v8h.24c2.42-4.58 8.32-9.41 17.13-9.41C103.6 47.28 107 59.35 107 75v32H88.89V78.65c0-6.75-.12-15.44-9.41-15.44s-10.87 7.36-10.87 15V107H50.53z"/></svg>](https://www.linkedin.com/in/mahmudun-nabi-kajal/)
|
|
120
|
+
for any questions or feedback! We hope Datatable Axios simplifies your data fetching process.
|
|
@@ -2,60 +2,91 @@
|
|
|
2
2
|
|
|
3
3
|
var axios = require('axios');
|
|
4
4
|
|
|
5
|
+
// Import the axios library
|
|
6
|
+
|
|
7
|
+
// Make the axios library globally available on the window object
|
|
5
8
|
window.axios = axios;
|
|
6
9
|
|
|
7
|
-
//
|
|
8
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
9
|
-
|
|
10
|
-
// Get individual query parameter values
|
|
10
|
+
// Import the axios instance from the local file "./axios"
|
|
11
11
|
|
|
12
|
+
// Parse the search parameters from the URL
|
|
13
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
12
14
|
|
|
13
15
|
class datatable {
|
|
14
16
|
constructor() {
|
|
15
|
-
|
|
16
|
-
// this.paginate = router.currentRoute.value.query.paginate
|
|
17
|
-
// this.search = router.currentRoute.value.query.search
|
|
17
|
+
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
// Method to perform a GET request
|
|
19
21
|
async get(url) {
|
|
20
|
-
//
|
|
21
|
-
// const paginate = router.currentRoute.value.query.paginate
|
|
22
|
-
// const search = router.currentRoute.value.query.search
|
|
22
|
+
// Retrieve values from search parameters
|
|
23
23
|
const page = searchParams.get('page');
|
|
24
24
|
const paginate = searchParams.get('paginate');
|
|
25
25
|
const search = searchParams.get('search');
|
|
26
26
|
|
|
27
|
+
// Return a Promise that resolves when the request completes
|
|
27
28
|
return new Promise(async (resolve) => {
|
|
28
29
|
if (!page && !paginate && !search) {
|
|
30
|
+
// If no search parameters, make a regular GET request
|
|
29
31
|
await window.axios.get(url).then(response => {
|
|
30
|
-
resolve(response);
|
|
32
|
+
resolve(response); // Resolve the Promise with the response
|
|
31
33
|
});
|
|
32
34
|
} else {
|
|
35
|
+
// If search parameters exist, append them to the URL
|
|
33
36
|
await window.axios.get(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
34
|
-
resolve(response);
|
|
37
|
+
resolve(response); // Resolve the Promise with the response
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
})
|
|
38
41
|
}
|
|
42
|
+
|
|
43
|
+
// Method to perform a POST request
|
|
39
44
|
async post(url) {
|
|
40
|
-
//
|
|
41
|
-
// const paginate = router.currentRoute.value.query.paginate
|
|
42
|
-
// const search = router.currentRoute.value.query.search
|
|
45
|
+
// Retrieve values from search parameters
|
|
43
46
|
const page = searchParams.get('page');
|
|
44
47
|
const paginate = searchParams.get('paginate');
|
|
45
48
|
const search = searchParams.get('search');
|
|
46
49
|
|
|
50
|
+
// Return a Promise that resolves when the request completes
|
|
47
51
|
return new Promise(async (resolve) => {
|
|
48
52
|
if (!page && !paginate && !search) {
|
|
53
|
+
// If no search parameters, make a regular POST request
|
|
49
54
|
await window.axios.post(url).then(response => {
|
|
50
|
-
resolve(response);
|
|
55
|
+
resolve(response); // Resolve the Promise with the response
|
|
51
56
|
});
|
|
52
57
|
} else {
|
|
58
|
+
// If search parameters exist, append them to the URL
|
|
53
59
|
await window.axios.post(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
54
|
-
resolve(response);
|
|
60
|
+
resolve(response); // Resolve the Promise with the response
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Method to perform a PUT request
|
|
67
|
+
async put(url) {
|
|
68
|
+
// Retrieve values from search parameters
|
|
69
|
+
const page = searchParams.get('page');
|
|
70
|
+
const paginate = searchParams.get('paginate');
|
|
71
|
+
const search = searchParams.get('search');
|
|
72
|
+
|
|
73
|
+
// Return a Promise that resolves when the request completes
|
|
74
|
+
return new Promise(async (resolve) => {
|
|
75
|
+
if (!page && !paginate && !search) {
|
|
76
|
+
// If no search parameters, make a regular PUT request
|
|
77
|
+
await window.axios.put(url).then(response => {
|
|
78
|
+
resolve(response); // Resolve the Promise with the response
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
// If search parameters exist, append them to the URL
|
|
82
|
+
await window.axios.put(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
83
|
+
resolve(response); // Resolve the Promise with the response
|
|
55
84
|
});
|
|
56
85
|
}
|
|
57
86
|
})
|
|
58
87
|
}
|
|
59
88
|
}
|
|
60
89
|
|
|
90
|
+
// Import the "datatable" class from the local file "./datatable"
|
|
91
|
+
|
|
61
92
|
module.exports = datatable;
|
|
@@ -1,59 +1,90 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
|
+
// Import the axios library
|
|
4
|
+
|
|
5
|
+
// Make the axios library globally available on the window object
|
|
3
6
|
window.axios = axios;
|
|
4
7
|
|
|
5
|
-
//
|
|
6
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
7
|
-
|
|
8
|
-
// Get individual query parameter values
|
|
8
|
+
// Import the axios instance from the local file "./axios"
|
|
9
9
|
|
|
10
|
+
// Parse the search parameters from the URL
|
|
11
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
10
12
|
|
|
11
13
|
class datatable {
|
|
12
14
|
constructor() {
|
|
13
|
-
|
|
14
|
-
// this.paginate = router.currentRoute.value.query.paginate
|
|
15
|
-
// this.search = router.currentRoute.value.query.search
|
|
15
|
+
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
// Method to perform a GET request
|
|
17
19
|
async get(url) {
|
|
18
|
-
//
|
|
19
|
-
// const paginate = router.currentRoute.value.query.paginate
|
|
20
|
-
// const search = router.currentRoute.value.query.search
|
|
20
|
+
// Retrieve values from search parameters
|
|
21
21
|
const page = searchParams.get('page');
|
|
22
22
|
const paginate = searchParams.get('paginate');
|
|
23
23
|
const search = searchParams.get('search');
|
|
24
24
|
|
|
25
|
+
// Return a Promise that resolves when the request completes
|
|
25
26
|
return new Promise(async (resolve) => {
|
|
26
27
|
if (!page && !paginate && !search) {
|
|
28
|
+
// If no search parameters, make a regular GET request
|
|
27
29
|
await window.axios.get(url).then(response => {
|
|
28
|
-
resolve(response);
|
|
30
|
+
resolve(response); // Resolve the Promise with the response
|
|
29
31
|
});
|
|
30
32
|
} else {
|
|
33
|
+
// If search parameters exist, append them to the URL
|
|
31
34
|
await window.axios.get(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
32
|
-
resolve(response);
|
|
35
|
+
resolve(response); // Resolve the Promise with the response
|
|
33
36
|
});
|
|
34
37
|
}
|
|
35
38
|
})
|
|
36
39
|
}
|
|
40
|
+
|
|
41
|
+
// Method to perform a POST request
|
|
37
42
|
async post(url) {
|
|
38
|
-
//
|
|
39
|
-
// const paginate = router.currentRoute.value.query.paginate
|
|
40
|
-
// const search = router.currentRoute.value.query.search
|
|
43
|
+
// Retrieve values from search parameters
|
|
41
44
|
const page = searchParams.get('page');
|
|
42
45
|
const paginate = searchParams.get('paginate');
|
|
43
46
|
const search = searchParams.get('search');
|
|
44
47
|
|
|
48
|
+
// Return a Promise that resolves when the request completes
|
|
45
49
|
return new Promise(async (resolve) => {
|
|
46
50
|
if (!page && !paginate && !search) {
|
|
51
|
+
// If no search parameters, make a regular POST request
|
|
47
52
|
await window.axios.post(url).then(response => {
|
|
48
|
-
resolve(response);
|
|
53
|
+
resolve(response); // Resolve the Promise with the response
|
|
49
54
|
});
|
|
50
55
|
} else {
|
|
56
|
+
// If search parameters exist, append them to the URL
|
|
51
57
|
await window.axios.post(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
52
|
-
resolve(response);
|
|
58
|
+
resolve(response); // Resolve the Promise with the response
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Method to perform a PUT request
|
|
65
|
+
async put(url) {
|
|
66
|
+
// Retrieve values from search parameters
|
|
67
|
+
const page = searchParams.get('page');
|
|
68
|
+
const paginate = searchParams.get('paginate');
|
|
69
|
+
const search = searchParams.get('search');
|
|
70
|
+
|
|
71
|
+
// Return a Promise that resolves when the request completes
|
|
72
|
+
return new Promise(async (resolve) => {
|
|
73
|
+
if (!page && !paginate && !search) {
|
|
74
|
+
// If no search parameters, make a regular PUT request
|
|
75
|
+
await window.axios.put(url).then(response => {
|
|
76
|
+
resolve(response); // Resolve the Promise with the response
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
// If search parameters exist, append them to the URL
|
|
80
|
+
await window.axios.put(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
81
|
+
resolve(response); // Resolve the Promise with the response
|
|
53
82
|
});
|
|
54
83
|
}
|
|
55
84
|
})
|
|
56
85
|
}
|
|
57
86
|
}
|
|
58
87
|
|
|
88
|
+
// Import the "datatable" class from the local file "./datatable"
|
|
89
|
+
|
|
59
90
|
export { datatable as default };
|
|
@@ -4,62 +4,93 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["datatable-axios"] = factory(global.axios));
|
|
5
5
|
})(this, (function (axios) { 'use strict';
|
|
6
6
|
|
|
7
|
+
// Import the axios library
|
|
8
|
+
|
|
9
|
+
// Make the axios library globally available on the window object
|
|
7
10
|
window.axios = axios;
|
|
8
11
|
|
|
9
|
-
//
|
|
10
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
11
|
-
|
|
12
|
-
// Get individual query parameter values
|
|
12
|
+
// Import the axios instance from the local file "./axios"
|
|
13
13
|
|
|
14
|
+
// Parse the search parameters from the URL
|
|
15
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
14
16
|
|
|
15
17
|
class datatable {
|
|
16
18
|
constructor() {
|
|
17
|
-
|
|
18
|
-
// this.paginate = router.currentRoute.value.query.paginate
|
|
19
|
-
// this.search = router.currentRoute.value.query.search
|
|
19
|
+
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
// Method to perform a GET request
|
|
21
23
|
async get(url) {
|
|
22
|
-
//
|
|
23
|
-
// const paginate = router.currentRoute.value.query.paginate
|
|
24
|
-
// const search = router.currentRoute.value.query.search
|
|
24
|
+
// Retrieve values from search parameters
|
|
25
25
|
const page = searchParams.get('page');
|
|
26
26
|
const paginate = searchParams.get('paginate');
|
|
27
27
|
const search = searchParams.get('search');
|
|
28
28
|
|
|
29
|
+
// Return a Promise that resolves when the request completes
|
|
29
30
|
return new Promise(async (resolve) => {
|
|
30
31
|
if (!page && !paginate && !search) {
|
|
32
|
+
// If no search parameters, make a regular GET request
|
|
31
33
|
await window.axios.get(url).then(response => {
|
|
32
|
-
resolve(response);
|
|
34
|
+
resolve(response); // Resolve the Promise with the response
|
|
33
35
|
});
|
|
34
36
|
} else {
|
|
37
|
+
// If search parameters exist, append them to the URL
|
|
35
38
|
await window.axios.get(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
36
|
-
resolve(response);
|
|
39
|
+
resolve(response); // Resolve the Promise with the response
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
})
|
|
40
43
|
}
|
|
44
|
+
|
|
45
|
+
// Method to perform a POST request
|
|
41
46
|
async post(url) {
|
|
42
|
-
//
|
|
43
|
-
// const paginate = router.currentRoute.value.query.paginate
|
|
44
|
-
// const search = router.currentRoute.value.query.search
|
|
47
|
+
// Retrieve values from search parameters
|
|
45
48
|
const page = searchParams.get('page');
|
|
46
49
|
const paginate = searchParams.get('paginate');
|
|
47
50
|
const search = searchParams.get('search');
|
|
48
51
|
|
|
52
|
+
// Return a Promise that resolves when the request completes
|
|
49
53
|
return new Promise(async (resolve) => {
|
|
50
54
|
if (!page && !paginate && !search) {
|
|
55
|
+
// If no search parameters, make a regular POST request
|
|
51
56
|
await window.axios.post(url).then(response => {
|
|
52
|
-
resolve(response);
|
|
57
|
+
resolve(response); // Resolve the Promise with the response
|
|
53
58
|
});
|
|
54
59
|
} else {
|
|
60
|
+
// If search parameters exist, append them to the URL
|
|
55
61
|
await window.axios.post(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
56
|
-
resolve(response);
|
|
62
|
+
resolve(response); // Resolve the Promise with the response
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Method to perform a PUT request
|
|
69
|
+
async put(url) {
|
|
70
|
+
// Retrieve values from search parameters
|
|
71
|
+
const page = searchParams.get('page');
|
|
72
|
+
const paginate = searchParams.get('paginate');
|
|
73
|
+
const search = searchParams.get('search');
|
|
74
|
+
|
|
75
|
+
// Return a Promise that resolves when the request completes
|
|
76
|
+
return new Promise(async (resolve) => {
|
|
77
|
+
if (!page && !paginate && !search) {
|
|
78
|
+
// If no search parameters, make a regular PUT request
|
|
79
|
+
await window.axios.put(url).then(response => {
|
|
80
|
+
resolve(response); // Resolve the Promise with the response
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
// If search parameters exist, append them to the URL
|
|
84
|
+
await window.axios.put(`${url}?page=${page}&paginate=${paginate}&search=${search}`).then(response => {
|
|
85
|
+
resolve(response); // Resolve the Promise with the response
|
|
57
86
|
});
|
|
58
87
|
}
|
|
59
88
|
})
|
|
60
89
|
}
|
|
61
90
|
}
|
|
62
91
|
|
|
92
|
+
// Import the "datatable" class from the local file "./datatable"
|
|
93
|
+
|
|
63
94
|
return datatable;
|
|
64
95
|
|
|
65
96
|
}));
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datatable-axios",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A powerful npm package for effortless datatable interactions with seamless Axios calls. Effortlessly integrate search, paginate, and pagination functionalities into your projects with ease.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/datatable-axios.js",
|
|
6
|
+
"main": "dist/datatable-axios.cjs.js",
|
|
7
7
|
"unpkg": "dist/datatable-axios.umd.js",
|
|
8
8
|
"jsdelivr": "dist/simple-datatables.umd.js",
|
|
9
9
|
"exports": {
|
|
10
|
-
"
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/datatable-axios.esm.js",
|
|
12
|
+
"require": "./dist/datatable-axios.cjs.js"
|
|
13
|
+
}
|
|
11
14
|
},
|
|
12
15
|
"scripts": {
|
|
13
16
|
"build": "npm run build:rollup",
|