utils-lib-js 1.3.3 → 1.4.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/dist/common/request.d.ts +18 -34
- package/dist/common/types.d.ts +2 -2
- package/dist/esm/request.d.ts +18 -34
- package/dist/esm/types.d.ts +2 -2
- package/package.json +42 -42
- package/pnpm-lock.yaml +1536 -1536
package/dist/common/request.d.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
13
|
-
constructor(origin:
|
|
14
|
-
abstract fetch(url:
|
|
15
|
-
abstract http(url:
|
|
16
|
-
chackUrl: (url:
|
|
17
|
-
checkIsHttps: (url:
|
|
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: () =>
|
|
19
|
+
envDesc: () => IEnv;
|
|
20
20
|
errorFn: (reject: any) => (err: any) => any;
|
|
21
21
|
clearTimer: (opts: any) => any;
|
|
22
|
-
initAbort: (params:
|
|
23
|
-
requestType: () =>
|
|
22
|
+
initAbort: (params: IRequestOptions) => IRequestOptions;
|
|
23
|
+
requestType: () => IRequestBaseFn;
|
|
24
24
|
getDataByType: (type: any, response: any) => any;
|
|
25
|
-
formatBodyString: (bodyString:
|
|
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:
|
|
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
|
-
|
|
48
|
-
|
|
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:
|
|
64
|
-
http: (_url:
|
|
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;
|
package/dist/common/types.d.ts
CHANGED
|
@@ -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):
|
|
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:
|
|
81
|
+
initAbort: (opts: IRequestOptions) => IRequestOptions;
|
|
82
82
|
requestType: () => IRequestBaseFn;
|
|
83
83
|
fixOrigin: (fixStr: string) => string;
|
|
84
84
|
fetch: IRequestBaseFn;
|
package/dist/esm/request.d.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
13
|
-
constructor(origin:
|
|
14
|
-
abstract fetch(url:
|
|
15
|
-
abstract http(url:
|
|
16
|
-
chackUrl: (url:
|
|
17
|
-
checkIsHttps: (url:
|
|
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: () =>
|
|
19
|
+
envDesc: () => IEnv;
|
|
20
20
|
errorFn: (reject: any) => (err: any) => any;
|
|
21
21
|
clearTimer: (opts: any) => any;
|
|
22
|
-
initAbort: (params:
|
|
23
|
-
requestType: () =>
|
|
22
|
+
initAbort: (params: IRequestOptions) => IRequestOptions;
|
|
23
|
+
requestType: () => IRequestBaseFn;
|
|
24
24
|
getDataByType: (type: any, response: any) => any;
|
|
25
|
-
formatBodyString: (bodyString:
|
|
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:
|
|
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
|
-
|
|
48
|
-
|
|
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:
|
|
64
|
-
http: (_url:
|
|
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;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -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):
|
|
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:
|
|
81
|
+
initAbort: (opts: IRequestOptions) => IRequestOptions;
|
|
82
82
|
requestType: () => IRequestBaseFn;
|
|
83
83
|
fixOrigin: (fixStr: string) => string;
|
|
84
84
|
fetch: IRequestBaseFn;
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "utils-lib-js",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "JavaScript工具函数,封装的一些常用的js函数",
|
|
5
|
-
"main": "./dist/common/index.js",
|
|
6
|
-
"types": "./dist/common/index.d.ts",
|
|
7
|
-
"module": "./dist/esm/index.js",
|
|
8
|
-
"exports": {
|
|
9
|
-
"import": "./dist/esm/index.js",
|
|
10
|
-
"require": "./dist/common/index.js"
|
|
11
|
-
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"babel
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "utils-lib-js",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "JavaScript工具函数,封装的一些常用的js函数",
|
|
5
|
+
"main": "./dist/common/index.js",
|
|
6
|
+
"types": "./dist/common/index.d.ts",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": "./dist/esm/index.js",
|
|
10
|
+
"require": "./dist/common/index.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"debug:esm": "start cmd /k pnpm run build:hot:esm",
|
|
14
|
+
"debug:node": "start cmd /k pnpm run build:hot:node & pnpm run node:hot",
|
|
15
|
+
"node:hot": "nodemon server.js",
|
|
16
|
+
"build:hot:esm": "tsc -p tsconfig.es.json -w",
|
|
17
|
+
"build:hot:node": "tsc -p tsconfig.json -w",
|
|
18
|
+
"build": "pnpm run tsc:build && pnpm run babel:mjs && pnpm run babel:cjs",
|
|
19
|
+
"tsc:build": "rm -fr dist && tsc -p tsconfig.json && tsc -p tsconfig.es.json",
|
|
20
|
+
"publish": "pnpm run build && pnpm publish",
|
|
21
|
+
"babel:mjs": "babel dist/esm --out-dir dist/esm",
|
|
22
|
+
"babel:cjs": "babel dist/common --out-dir dist/common",
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://gitee.com/DieHunter/utils-lib-js.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"utils",
|
|
31
|
+
"tools",
|
|
32
|
+
"lib"
|
|
33
|
+
],
|
|
34
|
+
"author": "",
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^18.7.15",
|
|
38
|
+
"babel-cli": "^6.26.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"abort-controller": "^3.0.0"
|
|
42
|
+
}
|
|
43
43
|
}
|