@jayfong/x-request 2.29.0 → 2.30.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/lib/_cjs/index.js CHANGED
@@ -77,12 +77,14 @@ exports.XRequestFormFile = XRequestFormFile;
77
77
  class XRequest {
78
78
  static getGotOptions(options, responseType) {
79
79
  var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
80
- if (options.query) {
81
- const url = new URL(options.url);
82
- const query = options.query instanceof URLSearchParams ? options.query : new URLSearchParams(options.query);
83
- query.forEach((v, k) => {
84
- url.searchParams.set(k, v);
85
- });
80
+ if (options.baseUrl || options.query) {
81
+ const url = new URL(options.url, options.baseUrl);
82
+ if (options.query) {
83
+ const query = options.query instanceof URLSearchParams ? options.query : new URLSearchParams(options.query);
84
+ query.forEach((v, k) => {
85
+ url.searchParams.set(k, v);
86
+ });
87
+ }
86
88
  options.url = url.toString();
87
89
  }
88
90
  const gotOptions = {
package/lib/index.d.ts CHANGED
@@ -7,6 +7,27 @@ import { Readable } from 'stream';
7
7
  import { CookieJar } from 'tough-cookie';
8
8
  import { OmitStrict } from 'vtils/types';
9
9
  export interface XRequestOptions {
10
+ /**
11
+ * 基础请求地址
12
+ *
13
+ * ```
14
+ * new URL('1111', 'https://baidu.com')
15
+ * // => https://baidu.com/1111
16
+ *
17
+ * new URL('1111', 'https://baidu.com/ddd')
18
+ * // => https://baidu.com/1111
19
+ *
20
+ * new URL('./1111', 'https://baidu.com/ddd/')
21
+ * // => https://baidu.com/ddd/1111
22
+ *
23
+ * new URL('/1111', 'https://baidu.com/ddd/')
24
+ * // => https://baidu.com/1111
25
+ *
26
+ * new URL('https://dddd.ddd', 'https://baidu.com/ddd/')
27
+ * // => https://dddd.ddd/
28
+ * ```
29
+ */
30
+ baseUrl?: string;
10
31
  /**
11
32
  * 请求地址
12
33
  */
package/lib/index.js CHANGED
@@ -68,12 +68,14 @@ export class XRequestFormFile {
68
68
  export class XRequest {
69
69
  static getGotOptions(options, responseType) {
70
70
  var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
71
- if (options.query) {
72
- const url = new URL(options.url);
73
- const query = options.query instanceof URLSearchParams ? options.query : new URLSearchParams(options.query);
74
- query.forEach((v, k) => {
75
- url.searchParams.set(k, v);
76
- });
71
+ if (options.baseUrl || options.query) {
72
+ const url = new URL(options.url, options.baseUrl);
73
+ if (options.query) {
74
+ const query = options.query instanceof URLSearchParams ? options.query : new URLSearchParams(options.query);
75
+ query.forEach((v, k) => {
76
+ url.searchParams.set(k, v);
77
+ });
78
+ }
77
79
  options.url = url.toString();
78
80
  }
79
81
  const gotOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-request",
3
- "version": "2.29.0",
3
+ "version": "2.30.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",