utils-lib-js 1.4.3 → 1.4.4

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,9 +28,8 @@ 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, method, query, headers, body, timeout, controller, type, ...others }: {
31
+ initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
32
32
  [x: string]: any;
33
- url?: string;
34
33
  method?: string;
35
34
  query?: {};
36
35
  headers?: {};
@@ -176,39 +176,35 @@ 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 (_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"]);
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);
179
+ _this.initDefaultParams = function (url, _a) {
180
+ var _b, _c;
181
+ var _d = _a.method,
182
+ method = _d === void 0 ? "GET" : _d,
183
+ _e = _a.query,
184
+ query = _e === void 0 ? {} : _e,
185
+ _f = _a.headers,
186
+ headers = _f === void 0 ? {} : _f,
187
+ _g = _a.body,
188
+ body = _g === void 0 ? null : _g,
189
+ _h = _a.timeout,
190
+ timeout = _h === void 0 ? 30 * 1000 : _h,
191
+ _j = _a.controller,
192
+ controller = _j === void 0 ? new CustomAbortController() : _j,
193
+ _k = _a.type,
194
+ type = _k === void 0 ? "json" : _k,
195
+ others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
196
+ var __params = __assign({ url: url, 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);
197
+ var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
198
+ params.url = (0, index_js_1.urlJoin)(_this.fixOrigin(url), query);
199
+ return params;
198
200
  };
199
201
  _this.initFetchParams = function (url, opts) {
200
- var _a, _b;
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));
202
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
204
203
  return _temp;
205
204
  };
206
205
  _this.initHttpParams = function (url, opts) {
207
- var _a, _b;
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));
211
- var options = parse(params.url, true);
206
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
207
+ var options = parse(_temp.url, true);
212
208
  return __assign(__assign({}, _temp), options);
213
209
  };
214
210
  return _this;
@@ -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: (opts: IRequestOptions) => any;
90
+ initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
91
91
  initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
92
92
  initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
93
93
  };
@@ -28,9 +28,8 @@ 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, method, query, headers, body, timeout, controller, type, ...others }: {
31
+ initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
32
32
  [x: string]: any;
33
- url?: string;
34
33
  method?: string;
35
34
  query?: {};
36
35
  headers?: {};
@@ -172,39 +172,35 @@ 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 (_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"]);
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);
175
+ _this.initDefaultParams = function (url, _a) {
176
+ var _b, _c;
177
+ var _d = _a.method,
178
+ method = _d === void 0 ? "GET" : _d,
179
+ _e = _a.query,
180
+ query = _e === void 0 ? {} : _e,
181
+ _f = _a.headers,
182
+ headers = _f === void 0 ? {} : _f,
183
+ _g = _a.body,
184
+ body = _g === void 0 ? null : _g,
185
+ _h = _a.timeout,
186
+ timeout = _h === void 0 ? 30 * 1000 : _h,
187
+ _j = _a.controller,
188
+ controller = _j === void 0 ? new CustomAbortController() : _j,
189
+ _k = _a.type,
190
+ type = _k === void 0 ? "json" : _k,
191
+ others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
192
+ var __params = __assign({ url: url, 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);
193
+ var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
194
+ params.url = urlJoin(_this.fixOrigin(url), query);
195
+ return params;
194
196
  };
195
197
  _this.initFetchParams = function (url, opts) {
196
- var _a, _b;
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));
198
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
200
199
  return _temp;
201
200
  };
202
201
  _this.initHttpParams = function (url, opts) {
203
- var _a, _b;
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));
207
- var options = parse(params.url, true);
202
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
203
+ var options = parse(_temp.url, true);
208
204
  return __assign(__assign({}, _temp), options);
209
205
  };
210
206
  return _this;
@@ -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: (opts: IRequestOptions) => any;
90
+ initDefaultParams: (url: IUrl, 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.3",
3
+ "version": "1.4.4",
4
4
  "description": "JavaScript工具函数,封装的一些常用的js函数",
5
5
  "main": "./dist/common/index.js",
6
6
  "types": "./dist/common/index.d.ts",