@modern-js/create-request 0.0.0-next-20221209071922 → 0.0.0-next-20221209080421

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.
@@ -1,51 +1,44 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { compile, pathToRegexp } from "path-to-regexp";
22
- import qs from "query-string";
1
+ import { compile, pathToRegexp } from 'path-to-regexp';
2
+ import qs from 'query-string';
23
3
  import { handleRes } from "./handleRes";
24
4
  let realRequest;
25
5
  let realAllowedHeaders;
26
6
  const originFetch = (...params) => fetch(...params).then(handleRes);
27
- const configure = (options) => {
28
- const { request, interceptor, allowedHeaders } = options;
7
+ export const configure = options => {
8
+ const {
9
+ request,
10
+ interceptor,
11
+ allowedHeaders
12
+ } = options;
29
13
  realRequest = request || originFetch;
30
14
  if (interceptor && !request) {
31
15
  realRequest = interceptor(fetch);
32
16
  }
33
17
  if (Array.isArray(allowedHeaders)) {
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
19
  realAllowedHeaders = allowedHeaders;
35
20
  }
36
21
  };
37
- const createRequest = (path, method, port, fetch2 = originFetch) => {
38
- const getFinalPath = compile(path, { encode: encodeURIComponent });
22
+ export const createRequest = (path, method, port,
23
+ // 后续可能要修改,暂时先保留
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ fetch = originFetch) => {
26
+ const getFinalPath = compile(path, {
27
+ encode: encodeURIComponent
28
+ });
39
29
  const keys = [];
40
30
  pathToRegexp(path, keys);
41
- const sender = (...args) => __async(void 0, null, function* () {
31
+ const sender = async (...args) => {
42
32
  const fetcher = realRequest || originFetch;
43
- const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
33
+ const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
44
34
  payload.params = payload.params || {};
45
35
  const requestParams = args[0];
46
- if (typeof requestParams === "object" && requestParams.params) {
47
- const { params } = requestParams;
48
- keys.forEach((key) => {
36
+ // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
37
+ if (typeof requestParams === 'object' && requestParams.params) {
38
+ const {
39
+ params
40
+ } = requestParams;
41
+ keys.forEach(key => {
49
42
  payload.params[key.name] = params[key.name];
50
43
  });
51
44
  } else {
@@ -56,18 +49,26 @@ const createRequest = (path, method, port, fetch2 = originFetch) => {
56
49
  const finalPath = getFinalPath(payload.params);
57
50
  const finalURL = payload.query ? `${finalPath}?${qs.stringify(payload.query)}` : finalPath;
58
51
  const headers = payload.headers || {};
59
- let body = payload.data && typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
52
+ let body = payload.data && typeof payload.data === 'object' ? JSON.stringify(payload.data) : payload.body;
60
53
  if (payload.data) {
61
- headers["Content-Type"] = "application/json";
62
- body = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
54
+ headers['Content-Type'] = 'application/json';
55
+ body = typeof payload.data === 'object' ? JSON.stringify(payload.data) : payload.body;
63
56
  } else if (payload.body) {
64
- headers["Content-Type"] = "text/plain";
57
+ headers['Content-Type'] = 'text/plain';
58
+ // eslint-disable-next-line prefer-destructuring
65
59
  body = payload.body;
66
60
  } else if (payload.formData) {
67
61
  body = payload.formData;
62
+ // https://stackoverflow.com/questions/44919424/bad-content-type-header-no-multipart-boundary-nodejs
63
+ // need multipart boundary aotu attached by browser when multipart is true
64
+ // headers['Content-Type'] = 'multipart/form-data';
68
65
  } else if (payload.formUrlencoded) {
69
- headers["Content-Type"] = "application/x-www-form-urlencoded";
70
- if (typeof payload.formUrlencoded === "object" && !(payload.formUrlencoded instanceof URLSearchParams)) {
66
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
67
+ if (typeof payload.formUrlencoded === 'object' &&
68
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69
+ // @ts-expect-error
70
+ // eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
71
+ !(payload.formUrlencoded instanceof URLSearchParams)) {
71
72
  body = qs.stringify(payload.formUrlencoded);
72
73
  } else {
73
74
  body = payload.formUrlencoded;
@@ -78,10 +79,6 @@ const createRequest = (path, method, port, fetch2 = originFetch) => {
78
79
  body,
79
80
  headers
80
81
  });
81
- });
82
+ };
82
83
  return sender;
83
- };
84
- export {
85
- configure,
86
- createRequest
87
- };
84
+ };
@@ -1,44 +1,24 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- const handleRes = (res) => __async(void 0, null, function* () {
22
- const contentType = res.headers.get("content-type");
1
+ const handleRes = async res => {
2
+ const contentType = res.headers.get('content-type');
3
+
4
+ // https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
23
5
  if (!res.ok) {
24
- const data = yield res.json();
6
+ const data = await res.json();
25
7
  res.data = data;
26
8
  throw res;
27
9
  }
28
- if ((contentType == null ? void 0 : contentType.includes("application/json")) || (contentType == null ? void 0 : contentType.includes("text/json"))) {
10
+ if (contentType !== null && contentType !== void 0 && contentType.includes('application/json') || contentType !== null && contentType !== void 0 && contentType.includes('text/json')) {
29
11
  return res.json();
30
12
  }
31
- if ((contentType == null ? void 0 : contentType.includes("text/html")) || (contentType == null ? void 0 : contentType.includes("text/plain"))) {
13
+ if (contentType !== null && contentType !== void 0 && contentType.includes('text/html') || contentType !== null && contentType !== void 0 && contentType.includes('text/plain')) {
32
14
  return res.text();
33
15
  }
34
- if (((contentType == null ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType == null ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
16
+ if ((contentType !== null && contentType !== void 0 && contentType.includes('application/x-www-form-urlencoded') || contentType !== null && contentType !== void 0 && contentType.includes('multipart/form-data')) && res instanceof Response) {
35
17
  return res.formData();
36
18
  }
37
- if (contentType == null ? void 0 : contentType.includes("application/octet-stream")) {
19
+ if (contentType !== null && contentType !== void 0 && contentType.includes('application/octet-stream')) {
38
20
  return res.arrayBuffer();
39
21
  }
40
22
  return res.text();
41
- });
42
- export {
43
- handleRes
44
23
  };
24
+ export { handleRes };
@@ -1,8 +1,5 @@
1
- import { isBrowser } from "@modern-js/utils";
1
+ import { isBrowser } from '@modern-js/utils';
2
2
  import { createRequest as browser } from "./browser";
3
3
  import { createRequest as node } from "./node";
4
4
  const createRequest = (...args) => isBrowser() ? browser(...args) : node(...args);
5
- var src_default = createRequest;
6
- export {
7
- src_default as default
8
- };
5
+ export default createRequest;
@@ -1,13 +1,17 @@
1
- import nodeFetch from "node-fetch";
2
- import { compile, pathToRegexp } from "path-to-regexp";
3
- import { useHeaders } from "@modern-js/utils/ssr";
4
- import qs from "query-string";
1
+ import nodeFetch from 'node-fetch';
2
+ import { compile, pathToRegexp } from 'path-to-regexp';
3
+ import { useHeaders } from '@modern-js/utils/ssr';
4
+ import qs from 'query-string';
5
5
  import { handleRes } from "./handleRes";
6
6
  let realRequest;
7
7
  let realAllowedHeaders = [];
8
8
  const originFetch = (...params) => nodeFetch(...params).then(handleRes);
9
- const configure = (options) => {
10
- const { request, interceptor, allowedHeaders } = options;
9
+ export const configure = options => {
10
+ const {
11
+ request,
12
+ interceptor,
13
+ allowedHeaders
14
+ } = options;
11
15
  realRequest = request || originFetch;
12
16
  if (interceptor && !request) {
13
17
  realRequest = interceptor(nodeFetch);
@@ -16,18 +20,26 @@ const configure = (options) => {
16
20
  realAllowedHeaders = allowedHeaders;
17
21
  }
18
22
  };
19
- const createRequest = (path, method, port, fetch = nodeFetch) => {
20
- const getFinalPath = compile(path, { encode: encodeURIComponent });
23
+ export const createRequest = (path, method, port,
24
+ // 后续可能要修改,暂时先保留
25
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
+ fetch = nodeFetch) => {
27
+ const getFinalPath = compile(path, {
28
+ encode: encodeURIComponent
29
+ });
21
30
  const keys = [];
22
31
  pathToRegexp(path, keys);
23
32
  const sender = (...args) => {
24
33
  const webRequestHeaders = useHeaders();
25
- const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
34
+ const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
26
35
  payload.params = payload.params || {};
27
36
  const requestParams = args[0];
28
- if (typeof requestParams === "object" && requestParams.params) {
29
- const { params } = requestParams;
30
- keys.forEach((key) => {
37
+ // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
38
+ if (typeof requestParams === 'object' && requestParams.params) {
39
+ const {
40
+ params
41
+ } = requestParams;
42
+ keys.forEach(key => {
31
43
  payload.params[key.name] = params[key.name];
32
44
  });
33
45
  } else {
@@ -40,21 +52,25 @@ const createRequest = (path, method, port, fetch = nodeFetch) => {
40
52
  const headers = payload.headers || {};
41
53
  let body;
42
54
  for (const key of realAllowedHeaders) {
43
- if (typeof webRequestHeaders[key] !== "undefined") {
55
+ if (typeof webRequestHeaders[key] !== 'undefined') {
44
56
  headers[key] = webRequestHeaders[key];
45
57
  }
46
58
  }
47
59
  if (payload.data) {
48
- headers["Content-Type"] = "application/json";
49
- body = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
60
+ headers['Content-Type'] = 'application/json';
61
+ body = typeof payload.data === 'object' ? JSON.stringify(payload.data) : payload.body;
50
62
  } else if (payload.body) {
51
- headers["Content-Type"] = "text/plain";
63
+ headers['Content-Type'] = 'text/plain';
64
+ // eslint-disable-next-line prefer-destructuring
52
65
  body = payload.body;
53
66
  } else if (payload.formData) {
54
67
  body = payload.formData;
68
+ // https://stackoverflow.com/questions/44919424/bad-content-type-header-no-multipart-boundary-nodejs
69
+ // need multipart boundary auto attached by node-fetch when multipart is true
70
+ // headers['Content-Type'] = 'multipart/form-data';
55
71
  } else if (payload.formUrlencoded) {
56
- headers["Content-Type"] = "application/x-www-form-urlencoded";
57
- if (typeof payload.formUrlencoded === "object") {
72
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
73
+ if (typeof payload.formUrlencoded === 'object') {
58
74
  body = qs.stringify(payload.formUrlencoded);
59
75
  } else {
60
76
  body = payload.formUrlencoded;
@@ -62,11 +78,11 @@ const createRequest = (path, method, port, fetch = nodeFetch) => {
62
78
  }
63
79
  const url = `http://localhost:${port}${finalPath}`;
64
80
  const fetcher = realRequest || originFetch;
65
- return fetcher(url, { method, body, headers });
81
+ return fetcher(url, {
82
+ method,
83
+ body,
84
+ headers
85
+ });
66
86
  };
67
87
  return sender;
68
- };
69
- export {
70
- configure,
71
- createRequest
72
- };
88
+ };
@@ -1,80 +1,52 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var stdin_exports = {};
25
- __export(stdin_exports, {
26
- configure: () => configure,
27
- createRequest: () => createRequest
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
28
5
  });
29
- module.exports = __toCommonJS(stdin_exports);
30
- var import_path_to_regexp = require("path-to-regexp");
31
- var import_query_string = __toESM(require("query-string"));
32
- var import_handleRes = require("./handleRes");
33
- var __async = (__this, __arguments, generator) => {
34
- return new Promise((resolve, reject) => {
35
- var fulfilled = (value) => {
36
- try {
37
- step(generator.next(value));
38
- } catch (e) {
39
- reject(e);
40
- }
41
- };
42
- var rejected = (value) => {
43
- try {
44
- step(generator.throw(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
- step((generator = generator.apply(__this, __arguments)).next());
51
- });
52
- };
6
+ exports.createRequest = exports.configure = void 0;
7
+ var _pathToRegexp = require("path-to-regexp");
8
+ var _queryString = _interopRequireDefault(require("query-string"));
9
+ var _handleRes = require("./handleRes");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
11
  let realRequest;
54
12
  let realAllowedHeaders;
55
- const originFetch = (...params) => fetch(...params).then(import_handleRes.handleRes);
56
- const configure = (options) => {
57
- const { request, interceptor, allowedHeaders } = options;
13
+ const originFetch = (...params) => fetch(...params).then(_handleRes.handleRes);
14
+ const configure = options => {
15
+ const {
16
+ request,
17
+ interceptor,
18
+ allowedHeaders
19
+ } = options;
58
20
  realRequest = request || originFetch;
59
21
  if (interceptor && !request) {
60
22
  realRequest = interceptor(fetch);
61
23
  }
62
24
  if (Array.isArray(allowedHeaders)) {
25
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
26
  realAllowedHeaders = allowedHeaders;
64
27
  }
65
28
  };
66
- const createRequest = (path, method, port, fetch2 = originFetch) => {
67
- const getFinalPath = (0, import_path_to_regexp.compile)(path, { encode: encodeURIComponent });
29
+ exports.configure = configure;
30
+ const createRequest = (path, method, port,
31
+ // 后续可能要修改,暂时先保留
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ fetch = originFetch) => {
34
+ const getFinalPath = (0, _pathToRegexp.compile)(path, {
35
+ encode: encodeURIComponent
36
+ });
68
37
  const keys = [];
69
- (0, import_path_to_regexp.pathToRegexp)(path, keys);
70
- const sender = (...args) => __async(void 0, null, function* () {
38
+ (0, _pathToRegexp.pathToRegexp)(path, keys);
39
+ const sender = async (...args) => {
71
40
  const fetcher = realRequest || originFetch;
72
- const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
41
+ const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
73
42
  payload.params = payload.params || {};
74
43
  const requestParams = args[0];
75
- if (typeof requestParams === "object" && requestParams.params) {
76
- const { params } = requestParams;
77
- keys.forEach((key) => {
44
+ // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
45
+ if (typeof requestParams === 'object' && requestParams.params) {
46
+ const {
47
+ params
48
+ } = requestParams;
49
+ keys.forEach(key => {
78
50
  payload.params[key.name] = params[key.name];
79
51
  });
80
52
  } else {
@@ -83,21 +55,29 @@ const createRequest = (path, method, port, fetch2 = originFetch) => {
83
55
  });
84
56
  }
85
57
  const finalPath = getFinalPath(payload.params);
86
- const finalURL = payload.query ? `${finalPath}?${import_query_string.default.stringify(payload.query)}` : finalPath;
58
+ const finalURL = payload.query ? `${finalPath}?${_queryString.default.stringify(payload.query)}` : finalPath;
87
59
  const headers = payload.headers || {};
88
- let body = payload.data && typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
60
+ let body = payload.data && typeof payload.data === 'object' ? JSON.stringify(payload.data) : payload.body;
89
61
  if (payload.data) {
90
- headers["Content-Type"] = "application/json";
91
- body = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
62
+ headers['Content-Type'] = 'application/json';
63
+ body = typeof payload.data === 'object' ? JSON.stringify(payload.data) : payload.body;
92
64
  } else if (payload.body) {
93
- headers["Content-Type"] = "text/plain";
65
+ headers['Content-Type'] = 'text/plain';
66
+ // eslint-disable-next-line prefer-destructuring
94
67
  body = payload.body;
95
68
  } else if (payload.formData) {
96
69
  body = payload.formData;
70
+ // https://stackoverflow.com/questions/44919424/bad-content-type-header-no-multipart-boundary-nodejs
71
+ // need multipart boundary aotu attached by browser when multipart is true
72
+ // headers['Content-Type'] = 'multipart/form-data';
97
73
  } else if (payload.formUrlencoded) {
98
- headers["Content-Type"] = "application/x-www-form-urlencoded";
99
- if (typeof payload.formUrlencoded === "object" && !(payload.formUrlencoded instanceof URLSearchParams)) {
100
- body = import_query_string.default.stringify(payload.formUrlencoded);
74
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
75
+ if (typeof payload.formUrlencoded === 'object' &&
76
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
77
+ // @ts-expect-error
78
+ // eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
79
+ !(payload.formUrlencoded instanceof URLSearchParams)) {
80
+ body = _queryString.default.stringify(payload.formUrlencoded);
101
81
  } else {
102
82
  body = payload.formUrlencoded;
103
83
  }
@@ -107,6 +87,7 @@ const createRequest = (path, method, port, fetch2 = originFetch) => {
107
87
  body,
108
88
  headers
109
89
  });
110
- });
90
+ };
111
91
  return sender;
112
92
  };
93
+ exports.createRequest = createRequest;
@@ -1,63 +1,30 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
20
- handleRes: () => handleRes
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
21
5
  });
22
- module.exports = __toCommonJS(stdin_exports);
23
- var __async = (__this, __arguments, generator) => {
24
- return new Promise((resolve, reject) => {
25
- var fulfilled = (value) => {
26
- try {
27
- step(generator.next(value));
28
- } catch (e) {
29
- reject(e);
30
- }
31
- };
32
- var rejected = (value) => {
33
- try {
34
- step(generator.throw(value));
35
- } catch (e) {
36
- reject(e);
37
- }
38
- };
39
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
40
- step((generator = generator.apply(__this, __arguments)).next());
41
- });
42
- };
43
- const handleRes = (res) => __async(void 0, null, function* () {
44
- const contentType = res.headers.get("content-type");
6
+ exports.handleRes = void 0;
7
+ const handleRes = async res => {
8
+ const contentType = res.headers.get('content-type');
9
+
10
+ // https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
45
11
  if (!res.ok) {
46
- const data = yield res.json();
12
+ const data = await res.json();
47
13
  res.data = data;
48
14
  throw res;
49
15
  }
50
- if ((contentType == null ? void 0 : contentType.includes("application/json")) || (contentType == null ? void 0 : contentType.includes("text/json"))) {
16
+ if (contentType !== null && contentType !== void 0 && contentType.includes('application/json') || contentType !== null && contentType !== void 0 && contentType.includes('text/json')) {
51
17
  return res.json();
52
18
  }
53
- if ((contentType == null ? void 0 : contentType.includes("text/html")) || (contentType == null ? void 0 : contentType.includes("text/plain"))) {
19
+ if (contentType !== null && contentType !== void 0 && contentType.includes('text/html') || contentType !== null && contentType !== void 0 && contentType.includes('text/plain')) {
54
20
  return res.text();
55
21
  }
56
- if (((contentType == null ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType == null ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
22
+ if ((contentType !== null && contentType !== void 0 && contentType.includes('application/x-www-form-urlencoded') || contentType !== null && contentType !== void 0 && contentType.includes('multipart/form-data')) && res instanceof Response) {
57
23
  return res.formData();
58
24
  }
59
- if (contentType == null ? void 0 : contentType.includes("application/octet-stream")) {
25
+ if (contentType !== null && contentType !== void 0 && contentType.includes('application/octet-stream')) {
60
26
  return res.arrayBuffer();
61
27
  }
62
28
  return res.text();
63
- });
29
+ };
30
+ exports.handleRes = handleRes;
@@ -1,27 +1,12 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
20
- default: () => src_default
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
21
5
  });
22
- module.exports = __toCommonJS(stdin_exports);
23
- var import_utils = require("@modern-js/utils");
24
- var import_browser = require("./browser");
25
- var import_node = require("./node");
26
- const createRequest = (...args) => (0, import_utils.isBrowser)() ? (0, import_browser.createRequest)(...args) : (0, import_node.createRequest)(...args);
27
- var src_default = createRequest;
6
+ exports.default = void 0;
7
+ var _utils = require("@modern-js/utils");
8
+ var _browser = require("./browser");
9
+ var _node = require("./node");
10
+ const createRequest = (...args) => (0, _utils.isBrowser)() ? (0, _browser.createRequest)(...args) : (0, _node.createRequest)(...args);
11
+ var _default = createRequest;
12
+ exports.default = _default;