utils-lib-js 1.3.3 → 1.4.1

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,40 +1,34 @@
1
- import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions } from "./index.js";
1
+ import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./index.js";
2
2
  declare class Interceptors implements IInterceptors {
3
3
  private requestSuccess;
4
4
  private responseSuccess;
5
5
  private error;
6
- use(type: any, fn: any): this;
6
+ use(type: "request" | "response" | "error", fn: Function): IInterceptors;
7
7
  get reqFn(): Function;
8
8
  get resFn(): Function;
9
9
  get errFn(): Function;
10
10
  }
11
11
  declare abstract class RequestBase extends Interceptors implements IRequestBase {
12
- readonly origin: string;
13
- constructor(origin: any);
14
- abstract fetch(url: any, opts: any): Promise<void>;
15
- abstract http(url: any, opts: any): Promise<void>;
16
- chackUrl: (url: string) => boolean;
17
- checkIsHttps: (url: string) => boolean;
12
+ readonly origin: IUrl;
13
+ constructor(origin: IUrl);
14
+ abstract fetch(url: string, opts: IRequestOptions): Promise<void>;
15
+ abstract http(url: string, opts: IRequestOptions): Promise<void>;
16
+ chackUrl: (url: IUrl) => boolean;
17
+ checkIsHttps: (url: IUrl) => boolean;
18
18
  fixOrigin: (fixStr: string) => string;
19
- envDesc: () => "Window" | "Node";
19
+ envDesc: () => IEnv;
20
20
  errorFn: (reject: any) => (err: any) => any;
21
21
  clearTimer: (opts: any) => any;
22
- initAbort: (params: any) => any;
23
- requestType: () => (url: any, opts: any) => Promise<void>;
22
+ initAbort: (params: IRequestOptions) => IRequestOptions;
23
+ requestType: () => IRequestBaseFn;
24
24
  getDataByType: (type: any, response: any) => any;
25
- formatBodyString: (bodyString: any) => {
26
- text: () => any;
27
- json: () => any;
28
- blob: () => IObject<any>;
29
- formData: () => IObject<any>;
30
- arrayBuffer: () => IObject<any>;
31
- };
25
+ formatBodyString: (bodyString: string) => IObject<Function>;
32
26
  }
33
27
  declare abstract class RequestInit extends RequestBase implements IRequestInit {
34
28
  constructor(origin: any);
35
29
  abstract fetch(url: any, opts: any): Promise<void>;
36
30
  abstract http(url: any, opts: any): Promise<void>;
37
- initDefaultParams: (url: any, { method, query, headers, body, timeout, controller, type, ...others }: {
31
+ initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
38
32
  [x: string]: any;
39
33
  method?: string;
40
34
  query?: {};
@@ -43,25 +37,15 @@ declare abstract class RequestInit extends RequestBase implements IRequestInit {
43
37
  timeout?: number;
44
38
  controller?: any;
45
39
  type?: string;
46
- }) => {
47
- url: string;
48
- method: string;
49
- headers: {};
50
- body: string;
51
- timeout: number;
52
- signal: any;
53
- controller: any;
54
- type: string;
55
- timer: any;
56
- };
57
- initFetchParams: (url: any, opts: any) => any;
58
- initHttpParams: (url: any, opts: any) => any;
40
+ }) => IRequestOptions;
41
+ initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
42
+ initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
59
43
  }
60
44
  export declare class Request extends RequestInit implements IRequest {
61
45
  private request;
62
46
  constructor(origin: any);
63
- fetch: (_url: any, _opts: any) => Promise<void>;
64
- http: (_url: any, _opts: any) => Promise<void>;
47
+ fetch: (_url: string, _opts: IRequestOptions) => Promise<any>;
48
+ http: (_url: string, _opts: IRequestOptions) => Promise<any>;
65
49
  GET: (url?: IUrl, query?: IObject<any>, _?: IRequestBody | void, opts?: IRequestOptions) => any;
66
50
  POST: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
67
51
  PUT: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
@@ -196,14 +196,16 @@ var RequestInit = function (_super) {
196
196
  };
197
197
  _this.initFetchParams = function (url, opts) {
198
198
  var _a, _b;
199
- var params = _this.initAbort(_this.initDefaultParams(url, opts));
200
- return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, params)) !== null && _b !== void 0 ? _b : params;
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
202
  };
202
203
  _this.initHttpParams = function (url, opts) {
203
204
  var _a, _b;
204
- var params = _this.initAbort(_this.initDefaultParams(url, opts));
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;
205
207
  var options = parse(params.url, true);
206
- return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __assign(__assign({}, params), options))) !== null && _b !== void 0 ? _b : __assign(__assign({}, params), options);
208
+ return __assign(__assign({}, params), options);
207
209
  };
208
210
  return _this;
209
211
  }
@@ -67,7 +67,7 @@ export declare type IRequestOptions = {
67
67
  [key: string]: any;
68
68
  };
69
69
  export declare type IInterceptors = {
70
- use(type: "request" | "response" | "error", fn: Function): void;
70
+ use(type: "request" | "response" | "error", fn: Function): IInterceptors;
71
71
  get reqFn(): Function;
72
72
  get resFn(): Function;
73
73
  get errFn(): Function;
@@ -78,7 +78,7 @@ export declare type IRequestBase = {
78
78
  envDesc: () => IEnv;
79
79
  errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
80
80
  clearTimer: (opts: IRequestOptions) => void;
81
- initAbort: <T = IRequestOptions>(opts: T) => T;
81
+ initAbort: (opts: IRequestOptions) => IRequestOptions;
82
82
  requestType: () => IRequestBaseFn;
83
83
  fixOrigin: (fixStr: string) => string;
84
84
  fetch: IRequestBaseFn;
@@ -1,40 +1,34 @@
1
- import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions } from "./index.js";
1
+ import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./index.js";
2
2
  declare class Interceptors implements IInterceptors {
3
3
  private requestSuccess;
4
4
  private responseSuccess;
5
5
  private error;
6
- use(type: any, fn: any): this;
6
+ use(type: "request" | "response" | "error", fn: Function): IInterceptors;
7
7
  get reqFn(): Function;
8
8
  get resFn(): Function;
9
9
  get errFn(): Function;
10
10
  }
11
11
  declare abstract class RequestBase extends Interceptors implements IRequestBase {
12
- readonly origin: string;
13
- constructor(origin: any);
14
- abstract fetch(url: any, opts: any): Promise<void>;
15
- abstract http(url: any, opts: any): Promise<void>;
16
- chackUrl: (url: string) => boolean;
17
- checkIsHttps: (url: string) => boolean;
12
+ readonly origin: IUrl;
13
+ constructor(origin: IUrl);
14
+ abstract fetch(url: string, opts: IRequestOptions): Promise<void>;
15
+ abstract http(url: string, opts: IRequestOptions): Promise<void>;
16
+ chackUrl: (url: IUrl) => boolean;
17
+ checkIsHttps: (url: IUrl) => boolean;
18
18
  fixOrigin: (fixStr: string) => string;
19
- envDesc: () => "Window" | "Node";
19
+ envDesc: () => IEnv;
20
20
  errorFn: (reject: any) => (err: any) => any;
21
21
  clearTimer: (opts: any) => any;
22
- initAbort: (params: any) => any;
23
- requestType: () => (url: any, opts: any) => Promise<void>;
22
+ initAbort: (params: IRequestOptions) => IRequestOptions;
23
+ requestType: () => IRequestBaseFn;
24
24
  getDataByType: (type: any, response: any) => any;
25
- formatBodyString: (bodyString: any) => {
26
- text: () => any;
27
- json: () => any;
28
- blob: () => IObject<any>;
29
- formData: () => IObject<any>;
30
- arrayBuffer: () => IObject<any>;
31
- };
25
+ formatBodyString: (bodyString: string) => IObject<Function>;
32
26
  }
33
27
  declare abstract class RequestInit extends RequestBase implements IRequestInit {
34
28
  constructor(origin: any);
35
29
  abstract fetch(url: any, opts: any): Promise<void>;
36
30
  abstract http(url: any, opts: any): Promise<void>;
37
- initDefaultParams: (url: any, { method, query, headers, body, timeout, controller, type, ...others }: {
31
+ initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
38
32
  [x: string]: any;
39
33
  method?: string;
40
34
  query?: {};
@@ -43,25 +37,15 @@ declare abstract class RequestInit extends RequestBase implements IRequestInit {
43
37
  timeout?: number;
44
38
  controller?: any;
45
39
  type?: string;
46
- }) => {
47
- url: string;
48
- method: string;
49
- headers: {};
50
- body: string;
51
- timeout: number;
52
- signal: any;
53
- controller: any;
54
- type: string;
55
- timer: any;
56
- };
57
- initFetchParams: (url: any, opts: any) => any;
58
- initHttpParams: (url: any, opts: any) => any;
40
+ }) => IRequestOptions;
41
+ initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
42
+ initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
59
43
  }
60
44
  export declare class Request extends RequestInit implements IRequest {
61
45
  private request;
62
46
  constructor(origin: any);
63
- fetch: (_url: any, _opts: any) => Promise<void>;
64
- http: (_url: any, _opts: any) => Promise<void>;
47
+ fetch: (_url: string, _opts: IRequestOptions) => Promise<any>;
48
+ http: (_url: string, _opts: IRequestOptions) => Promise<any>;
65
49
  GET: (url?: IUrl, query?: IObject<any>, _?: IRequestBody | void, opts?: IRequestOptions) => any;
66
50
  POST: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
67
51
  PUT: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
@@ -192,14 +192,16 @@ var RequestInit = function (_super) {
192
192
  };
193
193
  _this.initFetchParams = function (url, opts) {
194
194
  var _a, _b;
195
- var params = _this.initAbort(_this.initDefaultParams(url, opts));
196
- return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, params)) !== null && _b !== void 0 ? _b : params;
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
198
  };
198
199
  _this.initHttpParams = function (url, opts) {
199
200
  var _a, _b;
200
- var params = _this.initAbort(_this.initDefaultParams(url, opts));
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;
201
203
  var options = parse(params.url, true);
202
- return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __assign(__assign({}, params), options))) !== null && _b !== void 0 ? _b : __assign(__assign({}, params), options);
204
+ return __assign(__assign({}, params), options);
203
205
  };
204
206
  return _this;
205
207
  }
@@ -67,7 +67,7 @@ export declare type IRequestOptions = {
67
67
  [key: string]: any;
68
68
  };
69
69
  export declare type IInterceptors = {
70
- use(type: "request" | "response" | "error", fn: Function): void;
70
+ use(type: "request" | "response" | "error", fn: Function): IInterceptors;
71
71
  get reqFn(): Function;
72
72
  get resFn(): Function;
73
73
  get errFn(): Function;
@@ -78,7 +78,7 @@ export declare type IRequestBase = {
78
78
  envDesc: () => IEnv;
79
79
  errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
80
80
  clearTimer: (opts: IRequestOptions) => void;
81
- initAbort: <T = IRequestOptions>(opts: T) => T;
81
+ initAbort: (opts: IRequestOptions) => IRequestOptions;
82
82
  requestType: () => IRequestBaseFn;
83
83
  fixOrigin: (fixStr: string) => string;
84
84
  fetch: IRequestBaseFn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-lib-js",
3
- "version": "1.3.3",
3
+ "version": "1.4.1",
4
4
  "description": "JavaScript工具函数,封装的一些常用的js函数",
5
5
  "main": "./dist/common/index.js",
6
6
  "types": "./dist/common/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "build:hot:node": "tsc -p tsconfig.json -w",
36
36
  "build": "pnpm run tsc:build && pnpm run babel:mjs && pnpm run babel:cjs",
37
37
  "tsc:build": "rm -fr dist && tsc -p tsconfig.json && tsc -p tsconfig.es.json",
38
+ "build:publish": "pnpm run build && pnpm publish",
38
39
  "babel:mjs": "babel dist/esm --out-dir dist/esm",
39
40
  "babel:cjs": "babel dist/common --out-dir dist/common",
40
41
  "test": "echo \"Error: no test specified\" && exit 1"