utils-lib-js 1.4.2 → 1.4.3

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.
@@ -28,8 +28,9 @@ declare abstract class RequestInit extends RequestBase implements IRequestInit {
28
28
  constructor(origin: any);
29
29
  abstract fetch(url: any, opts: any): Promise<void>;
30
30
  abstract http(url: any, opts: any): Promise<void>;
31
- initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
31
+ initDefaultParams: ({ url, method, query, headers, body, timeout, controller, type, ...others }: {
32
32
  [x: string]: any;
33
+ url?: string;
33
34
  method?: string;
34
35
  query?: {};
35
36
  headers?: {};
@@ -176,36 +176,40 @@ var RequestInit = function (_super) {
176
176
  __extends(RequestInit, _super);
177
177
  function RequestInit(origin) {
178
178
  var _this = _super.call(this, origin) || this;
179
- _this.initDefaultParams = function (url, _a) {
180
- var _b = _a.method,
181
- method = _b === void 0 ? "GET" : _b,
182
- _c = _a.query,
183
- query = _c === void 0 ? {} : _c,
184
- _d = _a.headers,
185
- headers = _d === void 0 ? {} : _d,
186
- _e = _a.body,
187
- body = _e === void 0 ? null : _e,
188
- _f = _a.timeout,
189
- timeout = _f === void 0 ? 30 * 1000 : _f,
190
- _g = _a.controller,
191
- controller = _g === void 0 ? new CustomAbortController() : _g,
192
- _h = _a.type,
193
- type = _h === void 0 ? "json" : _h,
194
- others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
179
+ _this.initDefaultParams = function (_a) {
180
+ var _b = _a.url,
181
+ url = _b === void 0 ? "/" : _b,
182
+ _c = _a.method,
183
+ method = _c === void 0 ? "GET" : _c,
184
+ _d = _a.query,
185
+ query = _d === void 0 ? {} : _d,
186
+ _e = _a.headers,
187
+ headers = _e === void 0 ? {} : _e,
188
+ _f = _a.body,
189
+ body = _f === void 0 ? null : _f,
190
+ _g = _a.timeout,
191
+ timeout = _g === void 0 ? 30 * 1000 : _g,
192
+ _h = _a.controller,
193
+ controller = _h === void 0 ? new CustomAbortController() : _h,
194
+ _j = _a.type,
195
+ type = _j === void 0 ? "json" : _j,
196
+ others = __rest(_a, ["url", "method", "query", "headers", "body", "timeout", "controller", "type"]);
195
197
  return __assign({ url: (0, index_js_1.urlJoin)(_this.fixOrigin(url), query), method: method, headers: headers, body: method === "GET" ? null : (0, index_js_1.jsonToString)(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
196
198
  };
197
199
  _this.initFetchParams = function (url, opts) {
198
200
  var _a, _b;
199
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
200
- var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, _temp)) !== null && _b !== void 0 ? _b : _temp;
201
- return params;
201
+ var __p = __assign({ url: url }, opts);
202
+ var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __p)) !== null && _b !== void 0 ? _b : __p;
203
+ var _temp = _this.initAbort(_this.initDefaultParams(params));
204
+ return _temp;
202
205
  };
203
206
  _this.initHttpParams = function (url, opts) {
204
207
  var _a, _b;
205
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
206
- var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, _temp)) !== null && _b !== void 0 ? _b : _temp;
208
+ var __p = __assign({ url: url }, opts);
209
+ var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __p)) !== null && _b !== void 0 ? _b : __p;
210
+ var _temp = _this.initAbort(_this.initDefaultParams(params));
207
211
  var options = parse(params.url, true);
208
- return __assign(__assign({}, params), options);
212
+ return __assign(__assign({}, _temp), options);
209
213
  };
210
214
  return _this;
211
215
  }
@@ -87,7 +87,7 @@ export declare type IRequestBase = {
87
87
  formatBodyString: (bodyString: string) => IObject<Function>;
88
88
  };
89
89
  export declare type IRequestInit = {
90
- initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
90
+ initDefaultParams: (opts: IRequestOptions) => any;
91
91
  initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
92
92
  initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
93
93
  };
@@ -28,8 +28,9 @@ declare abstract class RequestInit extends RequestBase implements IRequestInit {
28
28
  constructor(origin: any);
29
29
  abstract fetch(url: any, opts: any): Promise<void>;
30
30
  abstract http(url: any, opts: any): Promise<void>;
31
- initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
31
+ initDefaultParams: ({ url, method, query, headers, body, timeout, controller, type, ...others }: {
32
32
  [x: string]: any;
33
+ url?: string;
33
34
  method?: string;
34
35
  query?: {};
35
36
  headers?: {};
@@ -172,36 +172,40 @@ var RequestInit = function (_super) {
172
172
  __extends(RequestInit, _super);
173
173
  function RequestInit(origin) {
174
174
  var _this = _super.call(this, origin) || this;
175
- _this.initDefaultParams = function (url, _a) {
176
- var _b = _a.method,
177
- method = _b === void 0 ? "GET" : _b,
178
- _c = _a.query,
179
- query = _c === void 0 ? {} : _c,
180
- _d = _a.headers,
181
- headers = _d === void 0 ? {} : _d,
182
- _e = _a.body,
183
- body = _e === void 0 ? null : _e,
184
- _f = _a.timeout,
185
- timeout = _f === void 0 ? 30 * 1000 : _f,
186
- _g = _a.controller,
187
- controller = _g === void 0 ? new CustomAbortController() : _g,
188
- _h = _a.type,
189
- type = _h === void 0 ? "json" : _h,
190
- others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
175
+ _this.initDefaultParams = function (_a) {
176
+ var _b = _a.url,
177
+ url = _b === void 0 ? "/" : _b,
178
+ _c = _a.method,
179
+ method = _c === void 0 ? "GET" : _c,
180
+ _d = _a.query,
181
+ query = _d === void 0 ? {} : _d,
182
+ _e = _a.headers,
183
+ headers = _e === void 0 ? {} : _e,
184
+ _f = _a.body,
185
+ body = _f === void 0 ? null : _f,
186
+ _g = _a.timeout,
187
+ timeout = _g === void 0 ? 30 * 1000 : _g,
188
+ _h = _a.controller,
189
+ controller = _h === void 0 ? new CustomAbortController() : _h,
190
+ _j = _a.type,
191
+ type = _j === void 0 ? "json" : _j,
192
+ others = __rest(_a, ["url", "method", "query", "headers", "body", "timeout", "controller", "type"]);
191
193
  return __assign({ url: urlJoin(_this.fixOrigin(url), query), method: method, headers: headers, body: method === "GET" ? null : jsonToString(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
192
194
  };
193
195
  _this.initFetchParams = function (url, opts) {
194
196
  var _a, _b;
195
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
196
- var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, _temp)) !== null && _b !== void 0 ? _b : _temp;
197
- return params;
197
+ var __p = __assign({ url: url }, opts);
198
+ var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __p)) !== null && _b !== void 0 ? _b : __p;
199
+ var _temp = _this.initAbort(_this.initDefaultParams(params));
200
+ return _temp;
198
201
  };
199
202
  _this.initHttpParams = function (url, opts) {
200
203
  var _a, _b;
201
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
202
- var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, _temp)) !== null && _b !== void 0 ? _b : _temp;
204
+ var __p = __assign({ url: url }, opts);
205
+ var params = (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __p)) !== null && _b !== void 0 ? _b : __p;
206
+ var _temp = _this.initAbort(_this.initDefaultParams(params));
203
207
  var options = parse(params.url, true);
204
- return __assign(__assign({}, params), options);
208
+ return __assign(__assign({}, _temp), options);
205
209
  };
206
210
  return _this;
207
211
  }
@@ -87,7 +87,7 @@ export declare type IRequestBase = {
87
87
  formatBodyString: (bodyString: string) => IObject<Function>;
88
88
  };
89
89
  export declare type IRequestInit = {
90
- initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
90
+ initDefaultParams: (opts: IRequestOptions) => any;
91
91
  initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
92
92
  initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
93
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-lib-js",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "JavaScript工具函数,封装的一些常用的js函数",
5
5
  "main": "./dist/common/index.js",
6
6
  "types": "./dist/common/index.d.ts",