@alessiofrittoli/fetcher 1.1.0 → 2.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.
Files changed (61) hide show
  1. package/README.md +83 -48
  2. package/dist/error/index.cjs +1 -0
  3. package/dist/error/index.d.cts +2 -0
  4. package/dist/error/index.d.mts +2 -0
  5. package/dist/error/index.mjs +1 -0
  6. package/dist/getErrorFromResponse-CIppVMTN.mjs +1 -0
  7. package/dist/getErrorFromResponse-D3OARgUA.cjs +1 -0
  8. package/dist/globals/index.d.cts +15 -0
  9. package/dist/globals/index.d.mts +15 -0
  10. package/dist/globals/index.mjs +1 -0
  11. package/dist/index-B8rmZCit.d.mts +398 -0
  12. package/dist/index-CQSGH5s-.d.cts +25 -0
  13. package/dist/index-CQSGH5s-.d.mts +25 -0
  14. package/dist/index-D-vZzzH1.d.cts +398 -0
  15. package/dist/index.cjs +1 -0
  16. package/dist/index.d.cts +17 -0
  17. package/dist/index.d.mts +16 -11
  18. package/dist/index.mjs +1 -0
  19. package/dist/ping/index.cjs +1 -0
  20. package/dist/ping/index.d.cts +9 -0
  21. package/dist/ping/index.d.mts +9 -0
  22. package/dist/ping/index.mjs +1 -0
  23. package/dist/types/index.cjs +0 -0
  24. package/dist/types/index.d.cts +2 -0
  25. package/dist/types/index.d.mts +2 -0
  26. package/dist/types/index.mjs +1 -0
  27. package/dist/xhr/index.cjs +1 -0
  28. package/dist/xhr/index.d.cts +2 -0
  29. package/dist/xhr/index.d.mts +2 -7
  30. package/dist/xhr/index.mjs +1 -1
  31. package/package.json +127 -156
  32. package/dist/chunk-HNNMLJIA.js +0 -1
  33. package/dist/chunk-LOWOZ6LK.mjs +0 -1
  34. package/dist/error.d.mts +0 -22
  35. package/dist/error.d.ts +0 -22
  36. package/dist/error.js +0 -1
  37. package/dist/error.mjs +0 -1
  38. package/dist/fetch.d.mts +0 -22
  39. package/dist/fetch.d.ts +0 -22
  40. package/dist/fetch.js +0 -1
  41. package/dist/fetch.mjs +0 -1
  42. package/dist/getErrorFromResponse-7V2YFS4F.js +0 -1
  43. package/dist/getErrorFromResponse-IJTUOFPH.mjs +0 -1
  44. package/dist/index.d.ts +0 -12
  45. package/dist/index.js +0 -1
  46. package/dist/logReadyStateChange-2QWX5XIU.mjs +0 -1
  47. package/dist/logReadyStateChange-MSYI3OBQ.js +0 -1
  48. package/dist/ping.d.mts +0 -8
  49. package/dist/ping.d.ts +0 -8
  50. package/dist/ping.js +0 -1
  51. package/dist/ping.mjs +0 -1
  52. package/dist/types-B7TKkr2l.d.ts +0 -227
  53. package/dist/types-DAKtp5Tp.d.mts +0 -227
  54. package/dist/types.d.mts +0 -7
  55. package/dist/types.d.ts +0 -7
  56. package/dist/types.js +0 -1
  57. package/dist/xhr/index.d.ts +0 -7
  58. package/dist/xhr/index.js +0 -1
  59. package/scripts/postinstall/index.js +0 -16
  60. package/scripts/postinstall/ts-setup.js +0 -15
  61. /package/dist/{types.mjs → globals/index.cjs} +0 -0
package/package.json CHANGED
@@ -1,157 +1,128 @@
1
1
  {
2
- "name": "@alessiofrittoli/fetcher",
3
- "version": "1.1.0",
4
- "description": "Typescript fetch/xhr utilities",
5
- "author": {
6
- "name": "Alessio Frittoli",
7
- "email": "info@alessiofrittoli.it",
8
- "url": "https://alessiofrittoli.it"
9
- },
10
- "license": "MIT",
11
- "funding": [
12
- {
13
- "type": "github",
14
- "url": "https://github.com/sponsors/alessiofrittoli"
15
- }
16
- ],
17
- "keywords": [
18
- "fetch",
19
- "ajax",
20
- "ping"
21
- ],
22
- "homepage": "https://github.com/alessiofrittoli/fetcher#readme",
23
- "bugs": {
24
- "url": "https://github.com/alessiofrittoli/fetcher/issues",
25
- "email": "info@alessiofrittoli.it"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/alessiofrittoli/fetcher.git"
30
- },
31
- "main": "./dist/index.js",
32
- "module": "./dist/index.mjs",
33
- "types": "./dist/index.d.ts",
34
- "files": [
35
- "dist",
36
- "scripts/postinstall"
37
- ],
38
- "exports": {
39
- ".": {
40
- "import": {
41
- "types": "./dist/index.d.mts",
42
- "default": "./dist/index.mjs"
43
- },
44
- "require": {
45
- "types": "./dist/index.d.ts",
46
- "default": "./dist/index.js"
47
- }
48
- },
49
- "./fetch": {
50
- "import": {
51
- "types": "./dist/fetch.d.mts",
52
- "default": "./dist/fetch.mjs"
53
- },
54
- "require": {
55
- "types": "./dist/fetch.d.ts",
56
- "default": "./dist/fetch.js"
57
- }
58
- },
59
- "./ping": {
60
- "import": {
61
- "types": "./dist/ping.d.mts",
62
- "default": "./dist/ping.mjs"
63
- },
64
- "require": {
65
- "types": "./dist/ping.d.ts",
66
- "default": "./dist/ping.js"
67
- }
68
- },
69
- "./xhr": {
70
- "import": {
71
- "types": "./dist/xhr/index.d.mts",
72
- "default": "./dist/xhr/index.mjs"
73
- },
74
- "require": {
75
- "types": "./dist/xhr/index.d.ts",
76
- "default": "./dist/xhr/index.js"
77
- }
78
- },
79
- "./error": {
80
- "import": {
81
- "types": "./dist/error.d.mts",
82
- "default": "./dist/error.mjs"
83
- },
84
- "require": {
85
- "types": "./dist/error.d.ts",
86
- "default": "./dist/error.js"
87
- }
88
- },
89
- "./types": {
90
- "import": {
91
- "types": "./dist/types.d.mts"
92
- },
93
- "require": {
94
- "types": "./dist/types.d.ts"
95
- }
96
- }
97
- },
98
- "sideEffects": false,
99
- "scripts": {
100
- "//1a": "*********************************************************************",
101
- "//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
102
- "//1c": "*********************************************************************",
103
- "dev": "cross-env NODE_ENV=development tsup --watch",
104
- "build:prod": "cross-env NODE_ENV=production tsup",
105
- "build": "pnpm lint && pnpm test:ci && pnpm build:prod",
106
- "lint": "eslint",
107
- "postinstall": "node scripts/postinstall/index.js",
108
- "release": "node scripts/release.js --verbose --npm",
109
- "//2a": "*********************************************************************",
110
- "//2b": "***************************** UNIT TESTS ****************************",
111
- "//2c": "*********************************************************************",
112
- "test": "jest --verbose",
113
- "test:watch": "jest --watchAll --verbose",
114
- "test:ci": "jest --ci --verbose",
115
- "//3a": "*********************************************************************",
116
- "//3b": "************************ UNIT TESTS COVERAGE ************************",
117
- "//3c": "*********************************************************************",
118
- "test:coverage": "pnpm test:watch --coverage",
119
- "test:coverage:ci": "pnpm test:ci --coverage",
120
- "test:serve-coverage": "http-server ./coverage/lcov-report --gzip true -p 0 -o --silent",
121
- "test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\"",
122
- "//4a": "*********************************************************************",
123
- "//4b": "************************ TARGETED UNIT TESTS ************************",
124
- "//4c": "*********************************************************************",
125
- "test:fetch": "pnpm test:watch fetch.test.ts"
126
- },
127
- "devDependencies": {
128
- "@alessiofrittoli/crypto-buffer": "^3.11.0",
129
- "@eslint/js": "^10.0.1",
130
- "@jest/globals": "^30.2.0",
131
- "@types/jest": "^30.0.0",
132
- "@types/node": "^25.2.3",
133
- "concurrently": "^9.2.1",
134
- "cross-env": "^10.1.0",
135
- "dotenv": "^17.3.1",
136
- "eslint": "^10.0.0",
137
- "globals": "^17.3.0",
138
- "http-server": "^14.1.1",
139
- "jest": "^30.2.0",
140
- "jest-environment-jsdom": "^30.2.0",
141
- "ts-jest": "^29.4.6",
142
- "ts-node": "^10.9.2",
143
- "tsup": "^8.5.1",
144
- "typescript": "^5.9.3",
145
- "typescript-eslint": "^8.55.0"
146
- },
147
- "dependencies": {
148
- "@alessiofrittoli/abort-controller": "^0.1.0",
149
- "@alessiofrittoli/chain-functions": "^2.5.0",
150
- "@alessiofrittoli/event-emitter": "^1.6.0",
151
- "@alessiofrittoli/exception": "^3.5.0",
152
- "@alessiofrittoli/node-scripts": "^3.3.0",
153
- "@alessiofrittoli/type-utils": "^1.9.0",
154
- "@alessiofrittoli/url-utils": "^3.7.1",
155
- "@alessiofrittoli/web-utils": "^1.20.0"
156
- }
157
- }
2
+ "name": "@alessiofrittoli/fetcher",
3
+ "version": "2.0.0",
4
+ "description": "Typescript fetch/xhr utilities",
5
+ "type": "module",
6
+ "author": {
7
+ "name": "Alessio Frittoli",
8
+ "email": "info@alessiofrittoli.it",
9
+ "url": "https://alessiofrittoli.it"
10
+ },
11
+ "license": "MIT",
12
+ "funding": [
13
+ {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/alessiofrittoli"
16
+ }
17
+ ],
18
+ "keywords": [
19
+ "fetch",
20
+ "xhr",
21
+ "XMLHttpRequest",
22
+ "ping"
23
+ ],
24
+ "homepage": "https://github.com/alessiofrittoli/fetcher#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/alessiofrittoli/fetcher/issues",
27
+ "email": "info@alessiofrittoli.it"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/alessiofrittoli/fetcher.git"
32
+ },
33
+ "engines": {
34
+ "node": ">=24.15.0",
35
+ "pnpm": ">=11.27.1"
36
+ },
37
+ "main": "./dist/index.cjs",
38
+ "module": "./dist/index.mjs",
39
+ "types": "./dist/index.d.mts",
40
+ "files": [
41
+ "dist"
42
+ ],
43
+ "exports": {
44
+ ".": {
45
+ "import": {
46
+ "types": "./dist/index.d.mts",
47
+ "default": "./dist/index.mjs"
48
+ },
49
+ "require": {
50
+ "types": "./dist/index.d.cts",
51
+ "default": "./dist/index.cjs"
52
+ }
53
+ },
54
+ "./*": {
55
+ "import": {
56
+ "types": "./dist/*/index.d.mts",
57
+ "default": "./dist/*/index.mjs"
58
+ },
59
+ "require": {
60
+ "types": "./dist/*/index.d.cts",
61
+ "default": "./dist/*/index.cjs"
62
+ }
63
+ }
64
+ },
65
+ "sideEffects": false,
66
+ "peerDependencies": {
67
+ "@alessiofrittoli/abort-controller": "^1.0.0",
68
+ "@alessiofrittoli/chain-functions": "^2.7.0",
69
+ "@alessiofrittoli/crypto-buffer": "^3.11.0",
70
+ "@alessiofrittoli/event-emitter": "^1.7.0",
71
+ "@alessiofrittoli/exception": "^4.1.1",
72
+ "@alessiofrittoli/math-utils": "^2.1.0",
73
+ "@alessiofrittoli/node-scripts": "^3.3.0",
74
+ "@alessiofrittoli/type-utils": "^2.0.0",
75
+ "@alessiofrittoli/url-utils": "^4.1.0",
76
+ "@alessiofrittoli/web-utils": "^2.4.0"
77
+ },
78
+ "devDependencies": {
79
+ "@alessiofrittoli/abort-controller": "^1.0.0",
80
+ "@alessiofrittoli/chain-functions": "^2.7.0",
81
+ "@alessiofrittoli/crypto-buffer": "^3.11.0",
82
+ "@alessiofrittoli/event-emitter": "^1.7.0",
83
+ "@alessiofrittoli/exception": "^4.1.1",
84
+ "@alessiofrittoli/math-utils": "^2.1.0",
85
+ "@alessiofrittoli/node-scripts": "^4.1.0",
86
+ "@alessiofrittoli/package-configs": "^1.6.0",
87
+ "@alessiofrittoli/type-utils": "^2.0.0",
88
+ "@alessiofrittoli/url-utils": "^4.1.0",
89
+ "@alessiofrittoli/web-utils": "^2.4.0",
90
+ "@types/node": "^24.19.1",
91
+ "@vitest/coverage-v8": "^5.0.5",
92
+ "concurrently": "^10.0.6",
93
+ "http-server": "^14.1.1",
94
+ "oxlint": "^1.89.0",
95
+ "prettier": "^3.9.10",
96
+ "prettier-plugin-sort-imports": "^1.8.11",
97
+ "tsdown": "^0.23.1",
98
+ "typescript": "^6.0.3",
99
+ "vite": "^8.3.5",
100
+ "vitest": "^5.0.5"
101
+ },
102
+ "scripts": {
103
+ "//1a": "*********************************************************************",
104
+ "//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
105
+ "//1c": "*********************************************************************",
106
+ "dev": "tsdown --watch",
107
+ "build": "pnpm lint && pnpm tsc && pnpm tsdown",
108
+ "lint": "oxlint --report-unused-disable-directives --max-warnings 0",
109
+ "release": "node scripts/release.ts --verbose --npm",
110
+ "//2a": "*********************************************************************",
111
+ "//2b": "***************************** UNIT TESTS ****************************",
112
+ "//2c": "*********************************************************************",
113
+ "test": "vitest --reporter=tree",
114
+ "test:watch": "pnpm test watch",
115
+ "test:ci": "pnpm test run",
116
+ "//3a": "*********************************************************************",
117
+ "//3b": "************************ UNIT TESTS COVERAGE ************************",
118
+ "//3c": "*********************************************************************",
119
+ "test:coverage": "pnpm test:watch --coverage",
120
+ "test:coverage:ci": "pnpm test:ci --coverage",
121
+ "test:serve-coverage": "http-server ./coverage --gzip true -p 0 -o /index.html --silent",
122
+ "test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\"",
123
+ "//4a": "*********************************************************************",
124
+ "//4b": "******************************* OTHER *******************************",
125
+ "//4c": "*********************************************************************",
126
+ "postinstall": "node scripts/postinstall/index.cjs"
127
+ }
128
+ }
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _code = require('@alessiofrittoli/exception/code');var o=(r=>(r.XHR_NOT_AVAILABLE="ERR:XHRNOTAVAILABLE",r.XHR_INVALID_STATE="ERR:XHRINVALIDSTATE",r))(o||{}),p= exports.b ={Exception:_code.ErrorCode,Request:o};exports.a = o; exports.b = p;
@@ -1 +0,0 @@
1
- import{ErrorCode as E}from"@alessiofrittoli/exception/code";var o=(r=>(r.XHR_NOT_AVAILABLE="ERR:XHRNOTAVAILABLE",r.XHR_INVALID_STATE="ERR:XHRINVALIDSTATE",r))(o||{}),t={Exception:E,Request:o};export{o as a,t as b};
package/dist/error.d.mts DELETED
@@ -1,22 +0,0 @@
1
- declare enum Request {
2
- XHR_NOT_AVAILABLE = "ERR:XHRNOTAVAILABLE",
3
- XHR_INVALID_STATE = "ERR:XHRINVALIDSTATE"
4
- }
5
- declare const ErrorCode: {
6
- Exception: {
7
- readonly UNKNOWN: "ERR:UNKNOWN";
8
- readonly ABORT: "ERR:ABORT";
9
- readonly EMPTY_VALUE: "ERR:EMPTYVALUE";
10
- readonly WRONG_VALUE: "ERR:WRONGVALUE";
11
- readonly EXPIRED: "ERR:EXPIRED";
12
- readonly TOO_EARLY: "ERR:TOOEARLY";
13
- readonly TOO_MANY: "ERR:TOOMANY";
14
- readonly QUOTA_REACHED: "ERR:QUOTAREACHED";
15
- readonly NOT_FOUND: "ERR:NOTFOUND";
16
- readonly OFFLINE: "ERR:INTERNETDISCONNECTED";
17
- };
18
- Request: typeof Request;
19
- };
20
- type ErrorCode = MergedEnumValue<typeof ErrorCode>;
21
-
22
- export { ErrorCode, Request };
package/dist/error.d.ts DELETED
@@ -1,22 +0,0 @@
1
- declare enum Request {
2
- XHR_NOT_AVAILABLE = "ERR:XHRNOTAVAILABLE",
3
- XHR_INVALID_STATE = "ERR:XHRINVALIDSTATE"
4
- }
5
- declare const ErrorCode: {
6
- Exception: {
7
- readonly UNKNOWN: "ERR:UNKNOWN";
8
- readonly ABORT: "ERR:ABORT";
9
- readonly EMPTY_VALUE: "ERR:EMPTYVALUE";
10
- readonly WRONG_VALUE: "ERR:WRONGVALUE";
11
- readonly EXPIRED: "ERR:EXPIRED";
12
- readonly TOO_EARLY: "ERR:TOOEARLY";
13
- readonly TOO_MANY: "ERR:TOOMANY";
14
- readonly QUOTA_REACHED: "ERR:QUOTAREACHED";
15
- readonly NOT_FOUND: "ERR:NOTFOUND";
16
- readonly OFFLINE: "ERR:INTERNETDISCONNECTED";
17
- };
18
- Request: typeof Request;
19
- };
20
- type ErrorCode = MergedEnumValue<typeof ErrorCode>;
21
-
22
- export { ErrorCode, Request };
package/dist/error.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHNNMLJIAjs = require('./chunk-HNNMLJIA.js');exports.ErrorCode = _chunkHNNMLJIAjs.b; exports.Request = _chunkHNNMLJIAjs.a;
package/dist/error.mjs DELETED
@@ -1 +0,0 @@
1
- import{a,b}from"./chunk-LOWOZ6LK.mjs";export{b as ErrorCode,a as Request};
package/dist/fetch.d.mts DELETED
@@ -1,22 +0,0 @@
1
- import { AbortSignal } from '@alessiofrittoli/abort-controller';
2
- import { F as Fetch } from './types-DAKtp5Tp.mjs';
3
- import '@alessiofrittoli/event-emitter';
4
- import '@alessiofrittoli/exception';
5
- import '@alessiofrittoli/exception/abort';
6
- import '@alessiofrittoli/url-utils';
7
- import './error.mjs';
8
-
9
- interface RequestInit extends globalThis.RequestInit {
10
- signal?: AbortSignal;
11
- }
12
- /**
13
- * An extended version of the global fetch API.
14
- *
15
- * @param input The RequestInfo | URL.
16
- * @param init The RequestInit.
17
- * @param onfulfilled (Optional) A callback to run on Request fulfill. This could be used to alter the returned result.
18
- * @returns An object with the parsed Request data, Request error, Request Response instance and Request Headers.
19
- */
20
- declare const fetch: <T, U extends RequestInit = RequestInit, V = Fetch.ReturnDataType<T, U>>(input: RequestInfo | URL, init?: U, onfulfilled?: Fetch.OnFulfilledCallback<V>) => Promise<Fetch.Result<V>>;
21
-
22
- export { fetch };
package/dist/fetch.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { AbortSignal } from '@alessiofrittoli/abort-controller';
2
- import { F as Fetch } from './types-B7TKkr2l.js';
3
- import '@alessiofrittoli/event-emitter';
4
- import '@alessiofrittoli/exception';
5
- import '@alessiofrittoli/exception/abort';
6
- import '@alessiofrittoli/url-utils';
7
- import './error.js';
8
-
9
- interface RequestInit extends globalThis.RequestInit {
10
- signal?: AbortSignal;
11
- }
12
- /**
13
- * An extended version of the global fetch API.
14
- *
15
- * @param input The RequestInfo | URL.
16
- * @param init The RequestInit.
17
- * @param onfulfilled (Optional) A callback to run on Request fulfill. This could be used to alter the returned result.
18
- * @returns An object with the parsed Request data, Request error, Request Response instance and Request Headers.
19
- */
20
- declare const fetch: <T, U extends RequestInit = RequestInit, V = Fetch.ReturnDataType<T, U>>(input: RequestInfo | URL, init?: U, onfulfilled?: Fetch.OnFulfilledCallback<V>) => Promise<Fetch.Result<V>>;
21
-
22
- export { fetch };
package/dist/fetch.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkHNNMLJIAjs = require('./chunk-HNNMLJIA.js');var _exception = require('@alessiofrittoli/exception');var h=(l,a,s)=>globalThis.fetch(l,a).then(async t=>{let o=t.headers,c=o.get("Content-Type"),i=_optionalChain([c, 'optionalAccess', _ => _.includes, 'call', _2 => _2("application/json")])||_optionalChain([a, 'optionalAccess', _3 => _3.responseType])==="json",u=_optionalChain([c, 'optionalAccess', _4 => _4.includes, 'call', _5 => _5("form-data")])||_optionalChain([a, 'optionalAccess', _6 => _6.responseType])==="formdata",e={response:t,headers:o,data:null,error:null};if(t.ok)return s?s(t):i?(e.data=await t.json(),e):u?(e.data=await t.formData(),e):_optionalChain([a, 'optionalAccess', _7 => _7.responseType])==="arraybuffer"?(e.data=await t.arrayBuffer(),e):_optionalChain([a, 'optionalAccess', _8 => _8.responseType])==="blob"?(e.data=await t.blob(),e):(e.data=await t.text(),e);if(i)throw await t.json();return e.error=new (0, _exception.Exception)(await t.text()||t.statusText,{code:_chunkHNNMLJIAjs.b.Exception.UNKNOWN}),e}).catch(t=>({data:null,headers:null,response:null,error:_exception.Exception.isException(t)?new (0, _exception.Exception)(t.message,{...t}):new (0, _exception.Exception)(t.message,{code:_chunkHNNMLJIAjs.b.Exception.UNKNOWN,name:t.name,cause:t})}));exports.fetch = h;
package/dist/fetch.mjs DELETED
@@ -1 +0,0 @@
1
- import{b as n}from"./chunk-LOWOZ6LK.mjs";import{Exception as r}from"@alessiofrittoli/exception";var m=(l,a,s)=>globalThis.fetch(l,a).then(async t=>{let o=t.headers,c=o.get("Content-Type"),i=c?.includes("application/json")||a?.responseType==="json",u=c?.includes("form-data")||a?.responseType==="formdata",e={response:t,headers:o,data:null,error:null};if(t.ok)return s?s(t):i?(e.data=await t.json(),e):u?(e.data=await t.formData(),e):a?.responseType==="arraybuffer"?(e.data=await t.arrayBuffer(),e):a?.responseType==="blob"?(e.data=await t.blob(),e):(e.data=await t.text(),e);if(i)throw await t.json();return e.error=new r(await t.text()||t.statusText,{code:n.Exception.UNKNOWN}),e}).catch(t=>({data:null,headers:null,response:null,error:r.isException(t)?new r(t.message,{...t}):new r(t.message,{code:n.Exception.UNKNOWN,name:t.name,cause:t})}));export{m as fetch};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _webutils = require('@alessiofrittoli/web-utils');var _cryptobuffer = require('@alessiofrittoli/crypto-buffer');var _exception = require('@alessiofrittoli/exception');var m=async n=>{let{response:s}=n,{responseType:o}=n;switch(o){case"document":break;case"json":{let e=s;if(e&&_exception.Exception.isException(e))return new (0, _exception.Exception)(e.message,{...e});break}case"":case"text":case"arraybuffer":case"blob":default:{let e=o==="arraybuffer"?_cryptobuffer.binaryToString.call(void 0, s):o==="blob"?await s.text():s;if(_webutils.isJson.call(void 0, e)){let t=JSON.parse(e);if(_exception.Exception.isException(t))return new (0, _exception.Exception)(t.message,{...t})}break}}return null};exports.getErrorFromResponse = m;
@@ -1 +0,0 @@
1
- import{isJson as a}from"@alessiofrittoli/web-utils";import{binaryToString as p}from"@alessiofrittoli/crypto-buffer";import{Exception as r}from"@alessiofrittoli/exception";var u=async n=>{let{response:s}=n,{responseType:o}=n;switch(o){case"document":break;case"json":{let e=s;if(e&&r.isException(e))return new r(e.message,{...e});break}case"":case"text":case"arraybuffer":case"blob":default:{let e=o==="arraybuffer"?p(s):o==="blob"?await s.text():s;if(a(e)){let t=JSON.parse(e);if(r.isException(t))return new r(t.message,{...t})}break}}return null};export{u as getErrorFromResponse};
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- declare global {
2
- interface RequestInit {
3
- /** The expected ResponseType. */
4
- responseType?: XMLHttpRequestResponseType | 'formdata';
5
- }
6
- interface ProgressEvent {
7
- readonly type: keyof XMLHttpRequestEventTargetEventMap;
8
- }
9
- }
10
- type DoNotUse = never;
11
-
12
- export type { DoNotUse };
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- var r=t=>{let e={event:"readystatechange",readyState:t.request.readyState,status:t.request.status,message:""};switch(t.request.readyState){case XMLHttpRequest.UNSENT:e.message="Request unsent";break;case XMLHttpRequest.OPENED:e.message="Request opened";break;case XMLHttpRequest.HEADERS_RECEIVED:e.message="Request headers received";break;case XMLHttpRequest.LOADING:e.message="Request loading";break;case XMLHttpRequest.DONE:e.message="Request done";break}t.log(e)};export{r as logReadyStateChange};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var a=t=>{let e={event:"readystatechange",readyState:t.request.readyState,status:t.request.status,message:""};switch(t.request.readyState){case XMLHttpRequest.UNSENT:e.message="Request unsent";break;case XMLHttpRequest.OPENED:e.message="Request opened";break;case XMLHttpRequest.HEADERS_RECEIVED:e.message="Request headers received";break;case XMLHttpRequest.LOADING:e.message="Request loading";break;case XMLHttpRequest.DONE:e.message="Request done";break}t.log(e)};exports.logReadyStateChange = a;
package/dist/ping.d.mts DELETED
@@ -1,8 +0,0 @@
1
- import { UrlInput } from '@alessiofrittoli/url-utils';
2
-
3
- /**
4
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon)
5
- */
6
- declare const ping: (url: UrlInput, data?: BodyInit | null) => void;
7
-
8
- export { ping };
package/dist/ping.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { UrlInput } from '@alessiofrittoli/url-utils';
2
-
3
- /**
4
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon)
5
- */
6
- declare const ping: (url: UrlInput, data?: BodyInit | null) => void;
7
-
8
- export { ping };
package/dist/ping.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _urlutils = require('@alessiofrittoli/url-utils');var l=(n,t)=>{navigator.sendBeacon(_urlutils.Url.format(n),t)};exports.ping = l;
package/dist/ping.mjs DELETED
@@ -1 +0,0 @@
1
- import{Url as o}from"@alessiofrittoli/url-utils";var a=(n,t)=>{navigator.sendBeacon(o.format(n),t)};export{a as ping};