@gjsify/fetch 0.0.3 → 0.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.
Files changed (88) hide show
  1. package/README.md +27 -2
  2. package/globals.mjs +12 -0
  3. package/lib/body.d.ts +69 -0
  4. package/lib/body.js +375 -0
  5. package/lib/errors/abort-error.d.ts +7 -0
  6. package/lib/errors/abort-error.js +9 -0
  7. package/lib/errors/base.d.ts +6 -0
  8. package/lib/errors/base.js +17 -0
  9. package/lib/errors/fetch-error.d.ts +16 -0
  10. package/lib/errors/fetch-error.js +23 -0
  11. package/lib/esm/body.js +104 -56
  12. package/lib/esm/errors/base.js +3 -1
  13. package/lib/esm/headers.js +116 -131
  14. package/lib/esm/index.js +145 -190
  15. package/lib/esm/request.js +42 -41
  16. package/lib/esm/response.js +19 -4
  17. package/lib/esm/utils/blob-from.js +2 -98
  18. package/lib/esm/utils/data-uri.js +23 -0
  19. package/lib/esm/utils/is.js +7 -3
  20. package/lib/esm/utils/multipart-parser.js +5 -2
  21. package/lib/esm/utils/referrer.js +10 -10
  22. package/lib/esm/utils/soup-helpers.js +22 -0
  23. package/lib/headers.d.ts +33 -0
  24. package/lib/headers.js +195 -0
  25. package/lib/index.d.ts +18 -0
  26. package/lib/index.js +205 -0
  27. package/lib/request.d.ts +101 -0
  28. package/lib/request.js +308 -0
  29. package/lib/response.d.ts +73 -0
  30. package/lib/response.js +158 -0
  31. package/lib/types/index.d.ts +1 -0
  32. package/lib/types/index.js +1 -0
  33. package/lib/types/system-error.d.ts +11 -0
  34. package/lib/types/system-error.js +2 -0
  35. package/lib/utils/blob-from.d.ts +2 -0
  36. package/lib/utils/blob-from.js +4 -0
  37. package/lib/utils/data-uri.d.ts +10 -0
  38. package/lib/utils/data-uri.js +27 -0
  39. package/lib/utils/get-search.d.ts +1 -0
  40. package/lib/utils/get-search.js +8 -0
  41. package/lib/utils/is-redirect.d.ts +7 -0
  42. package/lib/utils/is-redirect.js +10 -0
  43. package/lib/utils/is.d.ts +35 -0
  44. package/lib/utils/is.js +74 -0
  45. package/lib/utils/multipart-parser.d.ts +2 -0
  46. package/lib/utils/multipart-parser.js +396 -0
  47. package/lib/utils/referrer.d.ts +76 -0
  48. package/lib/utils/referrer.js +283 -0
  49. package/lib/utils/soup-helpers.d.ts +12 -0
  50. package/lib/utils/soup-helpers.js +25 -0
  51. package/package.json +23 -27
  52. package/src/body.ts +181 -169
  53. package/src/errors/base.ts +3 -1
  54. package/src/headers.ts +155 -202
  55. package/src/index.spec.ts +268 -3
  56. package/src/index.ts +199 -312
  57. package/src/request.ts +84 -75
  58. package/src/response.ts +48 -18
  59. package/src/test.mts +1 -1
  60. package/src/utils/blob-from.ts +4 -164
  61. package/src/utils/data-uri.ts +29 -0
  62. package/src/utils/is.ts +15 -15
  63. package/src/utils/multipart-parser.ts +3 -3
  64. package/src/utils/referrer.ts +11 -11
  65. package/src/utils/soup-helpers.ts +37 -0
  66. package/tsconfig.json +5 -5
  67. package/tsconfig.tsbuildinfo +1 -0
  68. package/lib/cjs/body.js +0 -255
  69. package/lib/cjs/errors/abort-error.js +0 -9
  70. package/lib/cjs/errors/base.js +0 -17
  71. package/lib/cjs/errors/fetch-error.js +0 -21
  72. package/lib/cjs/headers.js +0 -202
  73. package/lib/cjs/index.js +0 -224
  74. package/lib/cjs/request.js +0 -281
  75. package/lib/cjs/response.js +0 -133
  76. package/lib/cjs/types/index.js +0 -1
  77. package/lib/cjs/types/system-error.js +0 -1
  78. package/lib/cjs/utils/blob-from.js +0 -101
  79. package/lib/cjs/utils/get-search.js +0 -11
  80. package/lib/cjs/utils/is-redirect.js +0 -7
  81. package/lib/cjs/utils/is.js +0 -28
  82. package/lib/cjs/utils/multipart-parser.js +0 -353
  83. package/lib/cjs/utils/referrer.js +0 -153
  84. package/test.gjs.js +0 -34758
  85. package/test.gjs.mjs +0 -53177
  86. package/test.node.js +0 -1226
  87. package/test.node.mjs +0 -6294
  88. package/tsconfig.types.json +0 -8
@@ -1,281 +0,0 @@
1
- import "@girs/gjs";
2
- import "@girs/gio-2.0";
3
- import GLib from "@girs/glib-2.0";
4
- import Soup from "@girs/soup-3.0";
5
- import Gio from "@girs/gio-2.0";
6
- import * as SoupExt from "@gjsify/soup-3.0";
7
- import { URL } from "@gjsify/deno-runtime/ext/url/00_url";
8
- import Headers from "./headers.js";
9
- import Body, { clone, extractContentType, getTotalBytes } from "./body.js";
10
- import { isAbortSignal } from "./utils/is.js";
11
- import {
12
- validateReferrerPolicy,
13
- determineRequestsReferrer,
14
- DEFAULT_REFERRER_POLICY
15
- } from "./utils/referrer.js";
16
- const INTERNALS = Symbol("Request internals");
17
- const isRequest = (obj) => {
18
- return typeof obj === "object" && typeof obj.url === "string";
19
- };
20
- class Request extends Body {
21
- /** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
22
- cache;
23
- /** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
24
- credentials;
25
- /** Returns the kind of resource requested by request, e.g., "document" or "script". */
26
- destination;
27
- /** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
28
- get headers() {
29
- return this[INTERNALS].headers;
30
- }
31
- /** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
32
- integrity;
33
- /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
34
- keepalive;
35
- /** Returns request's HTTP method, which is "GET" by default. */
36
- get method() {
37
- return this[INTERNALS].method;
38
- }
39
- /** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
40
- mode;
41
- /** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
42
- get redirect() {
43
- return this[INTERNALS].redirect;
44
- }
45
- /**
46
- * Returns the referrer of request.
47
- * Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default.
48
- * This is used during fetching to determine the value of the `Referer` header of the request being made.
49
- * @see https://fetch.spec.whatwg.org/#dom-request-referrer
50
- **/
51
- get referrer() {
52
- if (this[INTERNALS].referrer === "no-referrer") {
53
- return "";
54
- }
55
- if (this[INTERNALS].referrer === "client") {
56
- return "about:client";
57
- }
58
- if (this[INTERNALS].referrer) {
59
- return this[INTERNALS].referrer.toString();
60
- }
61
- return void 0;
62
- }
63
- /** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
64
- get referrerPolicy() {
65
- return this[INTERNALS].referrerPolicy;
66
- }
67
- set referrerPolicy(referrerPolicy) {
68
- this[INTERNALS].referrerPolicy = validateReferrerPolicy(referrerPolicy);
69
- }
70
- /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
71
- get signal() {
72
- return this[INTERNALS].signal;
73
- }
74
- /** Returns the URL of request as a string. */
75
- get url() {
76
- return this[INTERNALS].parsedURL.toString();
77
- }
78
- get _uri() {
79
- return GLib.Uri.parse(this.url, GLib.UriFlags.NONE);
80
- }
81
- get _session() {
82
- return this[INTERNALS].session;
83
- }
84
- get _message() {
85
- return this[INTERNALS].message;
86
- }
87
- get _inputStream() {
88
- return this[INTERNALS].inputStream;
89
- }
90
- get [Symbol.toStringTag]() {
91
- return "Request";
92
- }
93
- [INTERNALS];
94
- // Node-fetch-only options
95
- follow;
96
- compress = false;
97
- counter = 0;
98
- agent = "";
99
- highWaterMark = 16384;
100
- insecureHTTPParser = false;
101
- constructor(input, init) {
102
- let parsedURL;
103
- let requestObj = {};
104
- if (isRequest(input)) {
105
- parsedURL = new URL(input.url);
106
- requestObj = input;
107
- } else {
108
- parsedURL = new URL(input);
109
- }
110
- if (parsedURL.username !== "" || parsedURL.password !== "") {
111
- throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
112
- }
113
- let method = init.method || requestObj.method || "GET";
114
- if (/^(delete|get|head|options|post|put)$/i.test(method)) {
115
- method = method.toUpperCase();
116
- }
117
- if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
118
- throw new TypeError("Request with GET/HEAD method cannot have body");
119
- }
120
- const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
121
- super(inputBody, {
122
- size: init.size || init.size || 0
123
- });
124
- const headers = new Headers(init.headers || input.headers || {});
125
- if (inputBody !== null && !headers.has("Content-Type")) {
126
- const contentType = extractContentType(inputBody, this);
127
- if (contentType) {
128
- headers.set("Content-Type", contentType);
129
- }
130
- }
131
- let signal = isRequest(input) ? input.signal : null;
132
- if ("signal" in init) {
133
- signal = init.signal;
134
- }
135
- if (signal != null && !isAbortSignal(signal)) {
136
- throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
137
- }
138
- let referrer = init.referrer == null ? input.referrer : init.referrer;
139
- if (referrer === "") {
140
- referrer = "no-referrer";
141
- } else if (referrer) {
142
- const parsedReferrer = new URL(referrer);
143
- referrer = /^about:(\/\/)?client$/.test(parsedReferrer.toString()) ? "client" : parsedReferrer;
144
- } else {
145
- referrer = void 0;
146
- }
147
- const session = SoupExt.ExtSession.new();
148
- const message = new Soup.Message({
149
- method,
150
- uri: this._uri
151
- });
152
- this[INTERNALS] = {
153
- method,
154
- redirect: init.redirect || input.redirect || "follow",
155
- headers,
156
- parsedURL,
157
- signal,
158
- referrer,
159
- referrerPolicy: "",
160
- session,
161
- message
162
- };
163
- this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
164
- this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
165
- this.counter = init.counter || input.counter || 0;
166
- this.agent = init.agent || input.agent;
167
- this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
168
- this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
169
- this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
170
- }
171
- /**
172
- * Custom send method using Soup, used in fetch to send the request
173
- * @param options
174
- * @returns
175
- */
176
- async _send(options) {
177
- options.headers._appendToSoupMessage(this._message);
178
- const cancellable = new Gio.Cancellable();
179
- this[INTERNALS].inputStream = await this._session.sendAsync(this._message, GLib.PRIORITY_DEFAULT, cancellable);
180
- this[INTERNALS].readable = this[INTERNALS].inputStream.toReadable({});
181
- return {
182
- inputStream: this[INTERNALS].inputStream,
183
- readable: this[INTERNALS].readable,
184
- cancellable
185
- };
186
- }
187
- /**
188
- * Clone this request
189
- */
190
- clone() {
191
- return new Request(this);
192
- }
193
- async arrayBuffer() {
194
- return super.arrayBuffer();
195
- }
196
- async blob() {
197
- return super.blob();
198
- }
199
- async formData() {
200
- return super.formData();
201
- }
202
- async json() {
203
- return super.json();
204
- }
205
- async text() {
206
- return super.text();
207
- }
208
- }
209
- Object.defineProperties(Request.prototype, {
210
- method: { enumerable: true },
211
- url: { enumerable: true },
212
- headers: { enumerable: true },
213
- redirect: { enumerable: true },
214
- clone: { enumerable: true },
215
- signal: { enumerable: true },
216
- referrer: { enumerable: true },
217
- referrerPolicy: { enumerable: true }
218
- });
219
- var request_default = Request;
220
- const getSoupRequestOptions = (request) => {
221
- const { parsedURL } = request[INTERNALS];
222
- const headers = new Headers(request[INTERNALS].headers);
223
- if (!headers.has("Accept")) {
224
- headers.set("Accept", "*/*");
225
- }
226
- let contentLengthValue = null;
227
- if (request.body === null && /^(post|put)$/i.test(request.method)) {
228
- contentLengthValue = "0";
229
- }
230
- if (request.body !== null) {
231
- const totalBytes = getTotalBytes(request);
232
- if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
233
- contentLengthValue = String(totalBytes);
234
- }
235
- }
236
- if (contentLengthValue) {
237
- headers.set("Content-Length", contentLengthValue);
238
- }
239
- if (request.referrerPolicy === "") {
240
- request.referrerPolicy = DEFAULT_REFERRER_POLICY;
241
- }
242
- if (request.referrer && request.referrer !== "no-referrer") {
243
- request[INTERNALS].referrer = determineRequestsReferrer(request);
244
- } else {
245
- request[INTERNALS].referrer = "no-referrer";
246
- }
247
- if (request[INTERNALS].referrer instanceof URL) {
248
- headers.set("Referer", request.referrer);
249
- }
250
- if (!headers.has("User-Agent")) {
251
- headers.set("User-Agent", "node-fetch");
252
- }
253
- if (request.compress && !headers.has("Accept-Encoding")) {
254
- headers.set("Accept-Encoding", "gzip, deflate, br");
255
- }
256
- let { agent } = request;
257
- if (typeof agent === "function") {
258
- agent = agent(parsedURL);
259
- }
260
- if (!headers.has("Connection") && !agent) {
261
- headers.set("Connection", "close");
262
- }
263
- const options = {
264
- // Overwrite search to retain trailing ? (issue #776)
265
- // path: parsedURL.pathname + search,
266
- // The following options are not expressed in the URL
267
- // method: request.method,
268
- headers
269
- // insecureHTTPParser: request.insecureHTTPParser,
270
- // agent
271
- };
272
- return {
273
- parsedURL,
274
- options
275
- };
276
- };
277
- export {
278
- Request,
279
- request_default as default,
280
- getSoupRequestOptions
281
- };
@@ -1,133 +0,0 @@
1
- import GLib from "@girs/glib-2.0";
2
- import Gio from "@girs/gio-2.0";
3
- import Headers from "./headers.js";
4
- import Body, { clone, extractContentType } from "./body.js";
5
- import { isRedirect } from "./utils/is-redirect.js";
6
- import { URL } from "@gjsify/deno-runtime/ext/url/00_url";
7
- const INTERNALS = Symbol("Response internals");
8
- class Response extends Body {
9
- [INTERNALS];
10
- _inputStream = null;
11
- constructor(body = null, options = {}) {
12
- super(body, options);
13
- const status = options.status != null ? options.status : 200;
14
- const headers = new Headers(options.headers);
15
- if (body !== null && !headers.has("Content-Type")) {
16
- const contentType = extractContentType(body, this);
17
- if (contentType) {
18
- headers.append("Content-Type", contentType);
19
- }
20
- }
21
- this[INTERNALS] = {
22
- type: "default",
23
- url: options.url,
24
- status,
25
- statusText: options.statusText || "",
26
- headers,
27
- counter: options.counter,
28
- highWaterMark: options.highWaterMark
29
- };
30
- }
31
- get type() {
32
- return this[INTERNALS].type;
33
- }
34
- get url() {
35
- return this[INTERNALS].url || "";
36
- }
37
- get status() {
38
- return this[INTERNALS].status;
39
- }
40
- /**
41
- * Convenience property representing if the request ended normally
42
- */
43
- get ok() {
44
- return this[INTERNALS].status >= 200 && this[INTERNALS].status < 300;
45
- }
46
- get redirected() {
47
- return this[INTERNALS].counter > 0;
48
- }
49
- get statusText() {
50
- return this[INTERNALS].statusText;
51
- }
52
- get headers() {
53
- return this[INTERNALS].headers;
54
- }
55
- get highWaterMark() {
56
- return this[INTERNALS].highWaterMark;
57
- }
58
- /**
59
- * Clone this response
60
- *
61
- * @return Response
62
- */
63
- // @ts-ignore
64
- clone() {
65
- return new Response(clone(this, this.highWaterMark), {
66
- type: this.type,
67
- url: this.url,
68
- status: this.status,
69
- statusText: this.statusText,
70
- headers: this.headers,
71
- ok: this.ok,
72
- redirected: this.redirected,
73
- size: this.size,
74
- highWaterMark: this.highWaterMark
75
- });
76
- }
77
- /**
78
- * @param url The URL that the new response is to originate from.
79
- * @param status An optional status code for the response (e.g., 302.)
80
- * @returns A Response object.
81
- */
82
- static redirect(url, status = 302) {
83
- if (!isRedirect(status)) {
84
- throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
85
- }
86
- return new Response(null, {
87
- headers: {
88
- location: new URL(url).toString()
89
- },
90
- status
91
- });
92
- }
93
- static error() {
94
- const response = new Response(null, { status: 0, statusText: "" });
95
- response[INTERNALS].type = "error";
96
- return response;
97
- }
98
- get [Symbol.toStringTag]() {
99
- return "Response";
100
- }
101
- async text() {
102
- if (!this._inputStream) {
103
- return super.text();
104
- }
105
- const outputStream = Gio.MemoryOutputStream.new_resizable();
106
- await new Promise((resolve, reject) => {
107
- outputStream.splice_async(this._inputStream, Gio.OutputStreamSpliceFlags.CLOSE_TARGET | Gio.OutputStreamSpliceFlags.CLOSE_SOURCE, GLib.PRIORITY_DEFAULT, null, (self, res) => {
108
- try {
109
- resolve(outputStream.splice_finish(res));
110
- } catch (error) {
111
- reject(error);
112
- }
113
- });
114
- });
115
- const bytes = outputStream.steal_as_bytes();
116
- return new TextDecoder().decode(bytes.toArray());
117
- }
118
- }
119
- Object.defineProperties(Response.prototype, {
120
- type: { enumerable: true },
121
- url: { enumerable: true },
122
- status: { enumerable: true },
123
- ok: { enumerable: true },
124
- redirected: { enumerable: true },
125
- statusText: { enumerable: true },
126
- headers: { enumerable: true },
127
- clone: { enumerable: true }
128
- });
129
- var response_default = Response;
130
- export {
131
- Response,
132
- response_default as default
133
- };
@@ -1 +0,0 @@
1
- export * from "./system-error.js";
@@ -1 +0,0 @@
1
- ;
@@ -1,101 +0,0 @@
1
- import { DOMException } from "@gjsify/deno-runtime/ext/web/01_dom_exception";
2
- import { Blob, File } from "@gjsify/deno-runtime/ext/web/09_file";
3
- import {
4
- realpathSync,
5
- statSync,
6
- rmdirSync,
7
- createReadStream,
8
- promises as fs
9
- } from "node:fs";
10
- import { basename, sep, join } from "node:path";
11
- import { tmpdir } from "node:os";
12
- import process from "node:process";
13
- const { stat, mkdtemp } = fs;
14
- let i = 0, tempDir, registry;
15
- const blobFromSync = (path, type) => fromBlob(statSync(path), path, type);
16
- const blobFrom = (path, type) => stat(path).then((stat2) => fromBlob(stat2, path, type));
17
- const fileFrom = (path, type) => stat(path).then((stat2) => fromFile(stat2, path, type));
18
- const fileFromSync = (path, type) => fromFile(statSync(path), path, type);
19
- const fromBlob = (stat2, path, type = "") => new Blob([new BlobDataItem({
20
- path,
21
- size: stat2.size,
22
- lastModified: stat2.mtimeMs,
23
- start: 0
24
- })], { type });
25
- const fromFile = (stat2, path, type = "") => new File([new BlobDataItem({
26
- path,
27
- size: stat2.size,
28
- lastModified: stat2.mtimeMs,
29
- start: 0
30
- })], basename(path), { type, lastModified: stat2.mtimeMs });
31
- const createTemporaryBlob = async (data, { signal, type } = {}) => {
32
- registry = registry || new FinalizationRegistry(fs.unlink);
33
- tempDir = tempDir || await mkdtemp(realpathSync(tmpdir()) + sep);
34
- const id = `${i++}`;
35
- const destination = join(tempDir, id);
36
- if (data instanceof ArrayBuffer)
37
- data = new Uint8Array(data);
38
- await fs.writeFile(destination, data, { signal });
39
- const blob = await blobFrom(destination, type);
40
- registry.register(blob, destination);
41
- return blob;
42
- };
43
- const createTemporaryFile = async (data, name, opts) => {
44
- const blob = await createTemporaryBlob(data);
45
- return new File([blob], name, opts);
46
- };
47
- class BlobDataItem {
48
- #path;
49
- #start;
50
- size;
51
- lastModified;
52
- originalSize;
53
- constructor(options) {
54
- this.#path = options.path;
55
- this.#start = options.start;
56
- this.size = options.size;
57
- this.lastModified = options.lastModified;
58
- this.originalSize = options.originalSize === void 0 ? options.size : options.originalSize;
59
- }
60
- /**
61
- * Slicing arguments is first validated and formatted
62
- * to not be out of range by Blob.prototype.slice
63
- */
64
- slice(start, end) {
65
- return new BlobDataItem({
66
- path: this.#path,
67
- lastModified: this.lastModified,
68
- originalSize: this.originalSize,
69
- size: end - start,
70
- start: this.#start + start
71
- });
72
- }
73
- async *stream() {
74
- const { mtimeMs, size } = await stat(this.#path);
75
- if (mtimeMs > this.lastModified || this.originalSize !== size) {
76
- throw new DOMException("The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.", "NotReadableError");
77
- }
78
- yield* createReadStream(this.#path, {
79
- start: this.#start,
80
- end: this.#start + this.size - 1
81
- });
82
- }
83
- get [Symbol.toStringTag]() {
84
- return "Blob";
85
- }
86
- }
87
- process.once("exit", () => {
88
- tempDir && rmdirSync(tempDir, { recursive: true });
89
- });
90
- var blob_from_default = blobFromSync;
91
- export {
92
- Blob,
93
- File,
94
- blobFrom,
95
- blobFromSync,
96
- createTemporaryBlob,
97
- createTemporaryFile,
98
- blob_from_default as default,
99
- fileFrom,
100
- fileFromSync
101
- };
@@ -1,11 +0,0 @@
1
- const getSearch = (parsedURL) => {
2
- if (parsedURL.search) {
3
- return parsedURL.search;
4
- }
5
- const lastOffset = parsedURL.href.length - 1;
6
- const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
7
- return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
8
- };
9
- export {
10
- getSearch
11
- };
@@ -1,7 +0,0 @@
1
- const redirectStatus = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
2
- const isRedirect = (code) => {
3
- return redirectStatus.has(code);
4
- };
5
- export {
6
- isRedirect
7
- };
@@ -1,28 +0,0 @@
1
- import { URL } from "@gjsify/deno-runtime/ext/url/00_url";
2
- const NAME = Symbol.toStringTag;
3
- const isURLSearchParameters = (object) => {
4
- return typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && typeof object.sort === "function" && object[NAME] === "URLSearchParams";
5
- };
6
- const isBlob = (value) => {
7
- return value && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && typeof value.constructor === "function" && /^(Blob|File)$/.test(value[NAME]);
8
- };
9
- const isAbortSignal = (object) => {
10
- return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
11
- };
12
- const isDomainOrSubdomain = (destination, original) => {
13
- const orig = new URL(original).hostname;
14
- const dest = new URL(destination).hostname;
15
- return orig === dest || orig.endsWith(`.${dest}`);
16
- };
17
- const isSameProtocol = (destination, original) => {
18
- const orig = new URL(original).protocol;
19
- const dest = new URL(destination).protocol;
20
- return orig === dest;
21
- };
22
- export {
23
- isAbortSignal,
24
- isBlob,
25
- isDomainOrSubdomain,
26
- isSameProtocol,
27
- isURLSearchParameters
28
- };