datatable-axios 0.0.9 → 1.1.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/package.json CHANGED
@@ -1,59 +1,78 @@
1
- {
2
- "name": "datatable-axios",
3
- "version": "0.0.9",
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
- "type": "module",
6
- "main": "dist/datatable-axios.cjs.js",
7
- "unpkg": "dist/datatable-axios.umd.js",
8
- "jsdelivr": "dist/simple-datatables.umd.js",
9
- "exports": {
10
- ".": {
11
- "import": "./dist/datatable-axios.esm.js",
12
- "require": "./dist/datatable-axios.cjs.js"
13
- }
14
- },
15
- "scripts": {
16
- "build": "npm run build:rollup",
17
- "build:vite": "vite build",
18
- "build:rollup": "rollup -c"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/mahmudunnabikajal/datatable-axios.git"
23
- },
24
- "keywords": [
25
- "datatable",
26
- "axiosdatatable",
27
- "datatableaxios",
28
- "datatable-axios",
29
- "DataTables",
30
- "DataTable",
31
- "table",
32
- "grid",
33
- "filter",
34
- "sort",
35
- "page",
36
- "javascript-plugin",
37
- "vite",
38
- "npm",
39
- "package"
40
- ],
41
- "author": "Mahmudun Nabi Kajal",
42
- "license": "MIT",
43
- "bugs": {
44
- "url": "https://github.com/mahmudunnabikajal/datatable-axios/issues"
45
- },
46
- "homepage": "https://mahmudunnabikajal.github.io/datatable-axios/",
47
- "peerDependencies": {
48
- "axios": "*"
49
- },
50
- "devDependencies": {
51
- "vite": "^4.4.9",
52
- "@rollup/plugin-commonjs": "^25.0.4",
53
- "@rollup/plugin-node-resolve": "^15.2.0",
54
- "rollup": "^3.28.0"
55
- },
56
- "dependencies": {
57
- "axios": "^1.4.0"
58
- }
59
- }
1
+ {
2
+ "name": "datatable-axios",
3
+ "version": "1.1.0",
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
+ "type": "module",
6
+ "main": "dist/datatable-axios.cjs.js",
7
+ "unpkg": "dist/datatable-axios.umd.js",
8
+ "jsdelivr": "dist/datatable-axios.umd.js",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/datatable-axios.esm.js",
12
+ "require": "./dist/datatable-axios.cjs.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build:rollup": "rollup -c",
17
+ "build": "npm run build:rollup",
18
+ "prepublishOnly": "npm run build",
19
+ "lint": "eslint .",
20
+ "lint:fix": "eslint . --fix",
21
+ "format": "prettier --write .",
22
+ "format:check": "prettier --check .",
23
+ "test": "node --test",
24
+ "test:coverage": "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info",
25
+ "update:deps": "npx npm-check-updates -i --format group"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/mahmudunnabikajal/datatable-axios.git"
30
+ },
31
+ "keywords": [
32
+ "datatable",
33
+ "datatableaxios",
34
+ "datatable-axios",
35
+ "axiosdatatable",
36
+ "DataTables",
37
+ "DataTable",
38
+ "table",
39
+ "grid",
40
+ "filter",
41
+ "sort",
42
+ "page",
43
+ "javascript-plugin",
44
+ "vite",
45
+ "npm",
46
+ "package"
47
+ ],
48
+ "author": "Mahmudun Nabi Kajal <mahmudunnabikajal@gmail.com (https://mahmudunnabikajal.com/)",
49
+ "license": "MIT",
50
+ "bugs": {
51
+ "url": "https://github.com/mahmudunnabikajal/datatable-axios/issues"
52
+ },
53
+ "homepage": "https://mahmudunnabikajal.github.io/datatable-axios/",
54
+ "peerDependencies": {
55
+ "axios": "*"
56
+ },
57
+ "devDependencies": {
58
+ "vite": "^4.4.9",
59
+ "@rollup/plugin-commonjs": "^25.0.4",
60
+ "@rollup/plugin-node-resolve": "^15.2.0",
61
+ "rollup": "^3.28.0",
62
+ "@eslint/js": "^10.0.1",
63
+ "eslint": "^10.10.0",
64
+ "eslint-config-prettier": "^10.1.8",
65
+ "eslint-plugin-prettier": "^5.5.6",
66
+ "globals": "^17.12.0",
67
+ "prettier": "^3.9.6",
68
+ "semantic-release": "^25.0.9",
69
+ "@semantic-release/commit-analyzer": "^13.0.1",
70
+ "@semantic-release/git": "^10.0.1",
71
+ "@semantic-release/github": "^12.0.9",
72
+ "@semantic-release/npm": "^13.1.5",
73
+ "@semantic-release/release-notes-generator": "^14.1.1"
74
+ },
75
+ "dependencies": {
76
+ "axios": "^1.4.0"
77
+ }
78
+ }
@@ -0,0 +1,6 @@
1
+ sonar.organization=mahmudunnabikajal
2
+ sonar.projectKey=mahmudunnabikajal_datatable-axios
3
+ sonar.sources=src
4
+ sonar.tests=test
5
+ sonar.exclusions=docs/**
6
+ sonar.javascript.lcov.reportPaths=lcov.info
@@ -0,0 +1,108 @@
1
+ import { test, describe, beforeEach } from "node:test";
2
+ import assert from "node:assert";
3
+ import datatable from "../src/datatable.js";
4
+
5
+ function setupWindow(search, mockAxios) {
6
+ globalThis.window = {
7
+ location: { search },
8
+ axios: mockAxios,
9
+ };
10
+ }
11
+
12
+ function mockAxios(recordCall) {
13
+ return {
14
+ get: (url) => {
15
+ recordCall("get", url);
16
+ return Promise.resolve({ data: { url } });
17
+ },
18
+ post: (url) => {
19
+ recordCall("post", url);
20
+ return Promise.resolve({ data: { url } });
21
+ },
22
+ put: (url) => {
23
+ recordCall("put", url);
24
+ return Promise.resolve({ data: { url } });
25
+ },
26
+ };
27
+ }
28
+
29
+ describe("datatable", () => {
30
+ let dt;
31
+ let calls;
32
+
33
+ beforeEach(() => {
34
+ dt = new datatable();
35
+ calls = [];
36
+ });
37
+
38
+ describe("without page/paginate/search params", () => {
39
+ beforeEach(() => {
40
+ setupWindow(
41
+ "",
42
+ mockAxios((method, url) => calls.push({ method, url })),
43
+ );
44
+ });
45
+
46
+ test("get() makes a plain GET request", async () => {
47
+ const response = await dt.get("/api/items");
48
+ assert.deepStrictEqual(calls, [{ method: "get", url: "/api/items" }]);
49
+ assert.strictEqual(response.data.url, "/api/items");
50
+ });
51
+
52
+ test("post() makes a plain POST request", async () => {
53
+ await dt.post("/api/items");
54
+ assert.deepStrictEqual(calls, [{ method: "post", url: "/api/items" }]);
55
+ });
56
+
57
+ test("put() makes a plain PUT request", async () => {
58
+ await dt.put("/api/items");
59
+ assert.deepStrictEqual(calls, [{ method: "put", url: "/api/items" }]);
60
+ });
61
+ });
62
+
63
+ describe("with page/paginate/search params", () => {
64
+ beforeEach(() => {
65
+ setupWindow(
66
+ "?page=2&paginate=10&search=foo",
67
+ mockAxios((method, url) => calls.push({ method, url })),
68
+ );
69
+ });
70
+
71
+ test("get() appends query params to the URL", async () => {
72
+ await dt.get("/api/items");
73
+ assert.deepStrictEqual(calls, [
74
+ { method: "get", url: "/api/items?page=2&paginate=10&search=foo" },
75
+ ]);
76
+ });
77
+
78
+ test("post() appends query params to the URL", async () => {
79
+ await dt.post("/api/items");
80
+ assert.deepStrictEqual(calls, [
81
+ { method: "post", url: "/api/items?page=2&paginate=10&search=foo" },
82
+ ]);
83
+ });
84
+
85
+ test("put() appends query params to the URL", async () => {
86
+ await dt.put("/api/items");
87
+ assert.deepStrictEqual(calls, [
88
+ { method: "put", url: "/api/items?page=2&paginate=10&search=foo" },
89
+ ]);
90
+ });
91
+ });
92
+
93
+ describe("with only a single search param present", () => {
94
+ beforeEach(() => {
95
+ setupWindow(
96
+ "?page=3",
97
+ mockAxios((method, url) => calls.push({ method, url })),
98
+ );
99
+ });
100
+
101
+ test("get() appends query params with nulls for missing params", async () => {
102
+ await dt.get("/api/items");
103
+ assert.deepStrictEqual(calls, [
104
+ { method: "get", url: "/api/items?page=3&paginate=null&search=null" },
105
+ ]);
106
+ });
107
+ });
108
+ });
@@ -1,30 +0,0 @@
1
- import c from "axios";
2
- window.axios = c;
3
- const e = new URLSearchParams(window.location.search);
4
- class r {
5
- constructor() {
6
- }
7
- async get(t) {
8
- const s = e.get("page"), n = e.get("paginate"), o = e.get("search");
9
- return new Promise(async (i) => {
10
- !s && !n && !o ? await window.axios.get(t).then((a) => {
11
- i(a);
12
- }) : await window.axios.get(`${t}?page=${s}&paginate=${n}&search=${o}`).then((a) => {
13
- i(a);
14
- });
15
- });
16
- }
17
- async post(t) {
18
- const s = e.get("page"), n = e.get("paginate"), o = e.get("search");
19
- return new Promise(async (i) => {
20
- !s && !n && !o ? await window.axios.post(t).then((a) => {
21
- i(a);
22
- }) : await window.axios.post(`${t}?page=${s}&paginate=${n}&search=${o}`).then((a) => {
23
- i(a);
24
- });
25
- });
26
- }
27
- }
28
- export {
29
- r as default
30
- };
@@ -1 +0,0 @@
1
- (function(t,e){typeof exports=="object"&&typeof module<"u"?module.exports=e(require("axios")):typeof define=="function"&&define.amd?define(["axios"],e):(t=typeof globalThis<"u"?globalThis:t||self,t["datatable-axios"]=e(t.axios))})(this,function(t){"use strict";window.axios=t;const e=new URLSearchParams(window.location.search);class p{constructor(){}async get(n){const s=e.get("page"),i=e.get("paginate"),o=e.get("search");return new Promise(async c=>{!s&&!i&&!o?await window.axios.get(n).then(a=>{c(a)}):await window.axios.get(`${n}?page=${s}&paginate=${i}&search=${o}`).then(a=>{c(a)})})}async post(n){const s=e.get("page"),i=e.get("paginate"),o=e.get("search");return new Promise(async c=>{!s&&!i&&!o?await window.axios.post(n).then(a=>{c(a)}):await window.axios.post(`${n}?page=${s}&paginate=${i}&search=${o}`).then(a=>{c(a)})})}}return p});