utils-lib-js 1.6.2 → 1.6.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.
- package/dist/bundle/array.d.ts +10 -0
- package/dist/bundle/base.d.ts +14 -0
- package/dist/bundle/element.d.ts +6 -0
- package/dist/bundle/event.d.ts +14 -0
- package/dist/bundle/function.d.ts +12 -0
- package/dist/bundle/index.d.ts +51 -0
- package/dist/bundle/index.js +1023 -0
- package/dist/bundle/object.d.ts +30 -0
- package/dist/bundle/request.d.ts +60 -0
- package/dist/bundle/static.d.ts +16 -0
- package/dist/bundle/storage.d.ts +9 -0
- package/dist/bundle/types.d.ts +103 -0
- package/dist/cjs/array.d.ts +10 -10
- package/dist/cjs/array.js +19 -19
- package/dist/cjs/base.d.ts +14 -14
- package/dist/cjs/base.js +56 -56
- package/dist/cjs/element.d.ts +6 -6
- package/dist/cjs/element.js +16 -16
- package/dist/cjs/event.d.ts +14 -14
- package/dist/cjs/event.js +53 -53
- package/dist/cjs/function.d.ts +12 -12
- package/dist/cjs/function.js +66 -66
- package/dist/cjs/index.d.ts +51 -51
- package/dist/cjs/index.js +54 -54
- package/dist/cjs/object.d.ts +30 -30
- package/dist/cjs/object.js +190 -190
- package/dist/cjs/request.d.ts +60 -60
- package/dist/cjs/request.js +239 -239
- package/dist/cjs/static.d.ts +16 -16
- package/dist/cjs/static.js +18 -18
- package/dist/cjs/storage.d.ts +9 -9
- package/dist/cjs/storage.js +41 -41
- package/dist/cjs/types.d.ts +103 -103
- package/dist/cjs/types.js +2 -2
- package/dist/esm/array.d.ts +10 -10
- package/dist/esm/array.js +13 -13
- package/dist/esm/base.d.ts +14 -14
- package/dist/esm/base.js +48 -48
- package/dist/esm/element.d.ts +6 -6
- package/dist/esm/element.js +12 -12
- package/dist/esm/event.d.ts +14 -14
- package/dist/esm/event.js +45 -45
- package/dist/esm/function.d.ts +12 -12
- package/dist/esm/function.js +59 -59
- package/dist/esm/index.d.ts +51 -51
- package/dist/esm/index.js +35 -35
- package/dist/esm/object.d.ts +30 -30
- package/dist/esm/object.js +174 -174
- package/dist/esm/request.d.ts +60 -60
- package/dist/esm/request.js +236 -236
- package/dist/esm/static.d.ts +16 -16
- package/dist/esm/static.js +15 -15
- package/dist/esm/storage.d.ts +9 -9
- package/dist/esm/storage.js +35 -35
- package/dist/esm/types.d.ts +103 -103
- package/dist/esm/types.js +1 -1
- package/dist/umd/array.d.ts +10 -0
- package/dist/umd/base.d.ts +14 -0
- package/dist/umd/element.d.ts +6 -0
- package/dist/umd/event.d.ts +14 -0
- package/dist/umd/function.d.ts +12 -0
- package/dist/umd/index.d.ts +51 -0
- package/dist/umd/index.js +1024 -0
- package/dist/umd/object.d.ts +30 -0
- package/dist/umd/request.d.ts +60 -0
- package/dist/umd/static.d.ts +16 -0
- package/dist/umd/storage.d.ts +9 -0
- package/dist/umd/types.d.ts +103 -0
- package/package.json +12 -4
- package/pnpm-lock.yaml +279 -8
- package/rollup.config.js +35 -0
- package/tsconfig.umd.json +6 -0
package/dist/esm/object.js
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
|
-
import { getType, getTypeByList } from "./index.js";
|
|
11
|
-
export var getValue = function (object, key, defaultValue) {
|
|
12
|
-
if (defaultValue === void 0) { defaultValue = ''; }
|
|
13
|
-
var paths = key.split('.');
|
|
14
|
-
for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
|
|
15
|
-
var i = paths_1[_i];
|
|
16
|
-
object = object[i];
|
|
17
|
-
if (object === undefined) {
|
|
18
|
-
return defaultValue;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return object;
|
|
22
|
-
};
|
|
23
|
-
export var setValue = function (object, key, value) {
|
|
24
|
-
if (value === void 0) { value = {}; }
|
|
25
|
-
var paths = key.split('.');
|
|
26
|
-
var last = paths[paths.length - 1];
|
|
27
|
-
var _object = object;
|
|
28
|
-
for (var _i = 0, paths_2 = paths; _i < paths_2.length; _i++) {
|
|
29
|
-
var i = paths_2[_i];
|
|
30
|
-
if (typeof _object !== "object" && _object !== undefined) {
|
|
31
|
-
return object;
|
|
32
|
-
}
|
|
33
|
-
!_object && (_object = {});
|
|
34
|
-
!_object[i] && (_object[i] = {});
|
|
35
|
-
last === i && (_object[last] = value);
|
|
36
|
-
_object = _object[i];
|
|
37
|
-
}
|
|
38
|
-
return object;
|
|
39
|
-
};
|
|
40
|
-
export var mixIn = function (target, source, overwrite) {
|
|
41
|
-
var _a;
|
|
42
|
-
if (source === void 0) { source = {}; }
|
|
43
|
-
if (overwrite === void 0) { overwrite = false; }
|
|
44
|
-
for (var k in source) {
|
|
45
|
-
for (var key in source[k]) {
|
|
46
|
-
var proto = (_a = target.prototype) !== null && _a !== void 0 ? _a : target;
|
|
47
|
-
if (target[key] === undefined || overwrite) {
|
|
48
|
-
proto[key] = source[k][key];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return target;
|
|
53
|
-
};
|
|
54
|
-
export var enumInversion = function (target) {
|
|
55
|
-
for (var key in target) {
|
|
56
|
-
var _key = target[key];
|
|
57
|
-
if (typeof _key === "string" && !!!target[_key]) {
|
|
58
|
-
target[_key] = key;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return target;
|
|
62
|
-
};
|
|
63
|
-
export var isNotObject = function (source, type) { return (typeof source !== "object" || type === 'null'); };
|
|
64
|
-
export var cloneDeep = function (target) {
|
|
65
|
-
var __type = getType(target);
|
|
66
|
-
if (isNotObject(target, __type))
|
|
67
|
-
return target;
|
|
68
|
-
var __init = createObjectVariable(__type, target);
|
|
69
|
-
if (__type === "map") {
|
|
70
|
-
target.forEach(function (value, key) {
|
|
71
|
-
__init.set(key, cloneDeep(value));
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
else if (__type === "set") {
|
|
75
|
-
target.forEach(function (value) {
|
|
76
|
-
__init.add(cloneDeep(value));
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
Reflect.ownKeys(target).forEach(function (keys) {
|
|
81
|
-
var desc = target[keys];
|
|
82
|
-
__init[keys] = cloneDeep(desc);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return __init;
|
|
86
|
-
};
|
|
87
|
-
export var createObjectVariable = function (type, source) {
|
|
88
|
-
if (source === void 0) { source = {}; }
|
|
89
|
-
switch (type) {
|
|
90
|
-
case "array":
|
|
91
|
-
return [];
|
|
92
|
-
case "function":
|
|
93
|
-
return source;
|
|
94
|
-
case "set":
|
|
95
|
-
return new Set();
|
|
96
|
-
case "map":
|
|
97
|
-
return new Map();
|
|
98
|
-
case "date":
|
|
99
|
-
return new Date(source);
|
|
100
|
-
case "regExp":
|
|
101
|
-
return new RegExp(source);
|
|
102
|
-
case "math":
|
|
103
|
-
return Math;
|
|
104
|
-
default:
|
|
105
|
-
return {};
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
export var createObject = function (source) {
|
|
109
|
-
function F() { }
|
|
110
|
-
F.prototype = source;
|
|
111
|
-
return new F();
|
|
112
|
-
};
|
|
113
|
-
export var inherit = function (source, target) {
|
|
114
|
-
if (target === void 0) { target = function () { }; }
|
|
115
|
-
target.prototype = createObject(source.prototype);
|
|
116
|
-
target.prototype.super = source;
|
|
117
|
-
target.prototype.constructor = target;
|
|
118
|
-
return target;
|
|
119
|
-
};
|
|
120
|
-
export var getInstance = function (classProto, overwrite) {
|
|
121
|
-
if (overwrite === void 0) { overwrite = false; }
|
|
122
|
-
var params = [];
|
|
123
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
124
|
-
params[_i - 2] = arguments[_i];
|
|
125
|
-
}
|
|
126
|
-
if (!classProto._instance || overwrite) {
|
|
127
|
-
classProto._instance = new (classProto.bind.apply(classProto, __spreadArray([void 0], params, false)))();
|
|
128
|
-
}
|
|
129
|
-
return classProto._instance;
|
|
130
|
-
};
|
|
131
|
-
export var classDecorator = function (params) {
|
|
132
|
-
return function (target) {
|
|
133
|
-
for (var key in params) {
|
|
134
|
-
if (!!!Reflect.has(target.prototype, key)) {
|
|
135
|
-
target.prototype[key] = params[key];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
export var stringToJson = function (target) {
|
|
141
|
-
if (getType(target) !== "string")
|
|
142
|
-
return null;
|
|
143
|
-
try {
|
|
144
|
-
return JSON.parse(target);
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
export var jsonToString = function (target) {
|
|
151
|
-
if (!getTypeByList(target, ["array", "object", "set", "map"]))
|
|
152
|
-
return "";
|
|
153
|
-
try {
|
|
154
|
-
return JSON.stringify(target);
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
return "";
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
export default {
|
|
161
|
-
getValue: getValue,
|
|
162
|
-
setValue: setValue,
|
|
163
|
-
mixIn: mixIn,
|
|
164
|
-
enumInversion: enumInversion,
|
|
165
|
-
isNotObject: isNotObject,
|
|
166
|
-
cloneDeep: cloneDeep,
|
|
167
|
-
createObjectVariable: createObjectVariable,
|
|
168
|
-
createObject: createObject,
|
|
169
|
-
inherit: inherit,
|
|
170
|
-
getInstance: getInstance,
|
|
171
|
-
classDecorator: classDecorator,
|
|
172
|
-
stringToJson: stringToJson,
|
|
173
|
-
jsonToString: jsonToString,
|
|
174
|
-
};
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import { getType, getTypeByList } from "./index.js";
|
|
11
|
+
export var getValue = function (object, key, defaultValue) {
|
|
12
|
+
if (defaultValue === void 0) { defaultValue = ''; }
|
|
13
|
+
var paths = key.split('.');
|
|
14
|
+
for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
|
|
15
|
+
var i = paths_1[_i];
|
|
16
|
+
object = object[i];
|
|
17
|
+
if (object === undefined) {
|
|
18
|
+
return defaultValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return object;
|
|
22
|
+
};
|
|
23
|
+
export var setValue = function (object, key, value) {
|
|
24
|
+
if (value === void 0) { value = {}; }
|
|
25
|
+
var paths = key.split('.');
|
|
26
|
+
var last = paths[paths.length - 1];
|
|
27
|
+
var _object = object;
|
|
28
|
+
for (var _i = 0, paths_2 = paths; _i < paths_2.length; _i++) {
|
|
29
|
+
var i = paths_2[_i];
|
|
30
|
+
if (typeof _object !== "object" && _object !== undefined) {
|
|
31
|
+
return object;
|
|
32
|
+
}
|
|
33
|
+
!_object && (_object = {});
|
|
34
|
+
!_object[i] && (_object[i] = {});
|
|
35
|
+
last === i && (_object[last] = value);
|
|
36
|
+
_object = _object[i];
|
|
37
|
+
}
|
|
38
|
+
return object;
|
|
39
|
+
};
|
|
40
|
+
export var mixIn = function (target, source, overwrite) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (source === void 0) { source = {}; }
|
|
43
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
44
|
+
for (var k in source) {
|
|
45
|
+
for (var key in source[k]) {
|
|
46
|
+
var proto = (_a = target.prototype) !== null && _a !== void 0 ? _a : target;
|
|
47
|
+
if (target[key] === undefined || overwrite) {
|
|
48
|
+
proto[key] = source[k][key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return target;
|
|
53
|
+
};
|
|
54
|
+
export var enumInversion = function (target) {
|
|
55
|
+
for (var key in target) {
|
|
56
|
+
var _key = target[key];
|
|
57
|
+
if (typeof _key === "string" && !!!target[_key]) {
|
|
58
|
+
target[_key] = key;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return target;
|
|
62
|
+
};
|
|
63
|
+
export var isNotObject = function (source, type) { return (typeof source !== "object" || type === 'null'); };
|
|
64
|
+
export var cloneDeep = function (target) {
|
|
65
|
+
var __type = getType(target);
|
|
66
|
+
if (isNotObject(target, __type))
|
|
67
|
+
return target;
|
|
68
|
+
var __init = createObjectVariable(__type, target);
|
|
69
|
+
if (__type === "map") {
|
|
70
|
+
target.forEach(function (value, key) {
|
|
71
|
+
__init.set(key, cloneDeep(value));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else if (__type === "set") {
|
|
75
|
+
target.forEach(function (value) {
|
|
76
|
+
__init.add(cloneDeep(value));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
Reflect.ownKeys(target).forEach(function (keys) {
|
|
81
|
+
var desc = target[keys];
|
|
82
|
+
__init[keys] = cloneDeep(desc);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return __init;
|
|
86
|
+
};
|
|
87
|
+
export var createObjectVariable = function (type, source) {
|
|
88
|
+
if (source === void 0) { source = {}; }
|
|
89
|
+
switch (type) {
|
|
90
|
+
case "array":
|
|
91
|
+
return [];
|
|
92
|
+
case "function":
|
|
93
|
+
return source;
|
|
94
|
+
case "set":
|
|
95
|
+
return new Set();
|
|
96
|
+
case "map":
|
|
97
|
+
return new Map();
|
|
98
|
+
case "date":
|
|
99
|
+
return new Date(source);
|
|
100
|
+
case "regExp":
|
|
101
|
+
return new RegExp(source);
|
|
102
|
+
case "math":
|
|
103
|
+
return Math;
|
|
104
|
+
default:
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
export var createObject = function (source) {
|
|
109
|
+
function F() { }
|
|
110
|
+
F.prototype = source;
|
|
111
|
+
return new F();
|
|
112
|
+
};
|
|
113
|
+
export var inherit = function (source, target) {
|
|
114
|
+
if (target === void 0) { target = function () { }; }
|
|
115
|
+
target.prototype = createObject(source.prototype);
|
|
116
|
+
target.prototype.super = source;
|
|
117
|
+
target.prototype.constructor = target;
|
|
118
|
+
return target;
|
|
119
|
+
};
|
|
120
|
+
export var getInstance = function (classProto, overwrite) {
|
|
121
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
122
|
+
var params = [];
|
|
123
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
124
|
+
params[_i - 2] = arguments[_i];
|
|
125
|
+
}
|
|
126
|
+
if (!classProto._instance || overwrite) {
|
|
127
|
+
classProto._instance = new (classProto.bind.apply(classProto, __spreadArray([void 0], params, false)))();
|
|
128
|
+
}
|
|
129
|
+
return classProto._instance;
|
|
130
|
+
};
|
|
131
|
+
export var classDecorator = function (params) {
|
|
132
|
+
return function (target) {
|
|
133
|
+
for (var key in params) {
|
|
134
|
+
if (!!!Reflect.has(target.prototype, key)) {
|
|
135
|
+
target.prototype[key] = params[key];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export var stringToJson = function (target) {
|
|
141
|
+
if (getType(target) !== "string")
|
|
142
|
+
return null;
|
|
143
|
+
try {
|
|
144
|
+
return JSON.parse(target);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
export var jsonToString = function (target) {
|
|
151
|
+
if (!getTypeByList(target, ["array", "object", "set", "map"]))
|
|
152
|
+
return "";
|
|
153
|
+
try {
|
|
154
|
+
return JSON.stringify(target);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
export default {
|
|
161
|
+
getValue: getValue,
|
|
162
|
+
setValue: setValue,
|
|
163
|
+
mixIn: mixIn,
|
|
164
|
+
enumInversion: enumInversion,
|
|
165
|
+
isNotObject: isNotObject,
|
|
166
|
+
cloneDeep: cloneDeep,
|
|
167
|
+
createObjectVariable: createObjectVariable,
|
|
168
|
+
createObject: createObject,
|
|
169
|
+
inherit: inherit,
|
|
170
|
+
getInstance: getInstance,
|
|
171
|
+
classDecorator: classDecorator,
|
|
172
|
+
stringToJson: stringToJson,
|
|
173
|
+
jsonToString: jsonToString,
|
|
174
|
+
};
|
package/dist/esm/request.d.ts
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./index.js";
|
|
2
|
-
declare class Interceptors implements IInterceptors {
|
|
3
|
-
private requestSuccess;
|
|
4
|
-
private responseSuccess;
|
|
5
|
-
private error;
|
|
6
|
-
use(type: "request" | "response" | "error", fn: Function): IInterceptors;
|
|
7
|
-
get reqFn(): Function;
|
|
8
|
-
get resFn(): Function;
|
|
9
|
-
get errFn(): Function;
|
|
10
|
-
}
|
|
11
|
-
declare abstract class RequestBase extends Interceptors implements IRequestBase {
|
|
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
|
-
fixOrigin: (fixStr: string) => string;
|
|
19
|
-
envDesc: () => IEnv;
|
|
20
|
-
errorFn: (reject: any) => (err: any) => any;
|
|
21
|
-
clearTimer: (opts: any) => any;
|
|
22
|
-
initAbort: (params: IRequestOptions) => IRequestOptions;
|
|
23
|
-
requestType: () => IRequestBaseFn;
|
|
24
|
-
getDataByType: (type: any, response: any) => any;
|
|
25
|
-
formatBodyString: (bodyString: string) => IObject<Function>;
|
|
26
|
-
}
|
|
27
|
-
declare abstract class RequestInit extends RequestBase implements IRequestInit {
|
|
28
|
-
constructor(origin: any);
|
|
29
|
-
abstract fetch(url: any, opts: any): Promise<void>;
|
|
30
|
-
abstract http(url: any, opts: any): Promise<void>;
|
|
31
|
-
initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
|
|
32
|
-
[x: string]: any;
|
|
33
|
-
method?: string;
|
|
34
|
-
query?: {};
|
|
35
|
-
headers?: {};
|
|
36
|
-
body?: any;
|
|
37
|
-
timeout?: number;
|
|
38
|
-
controller?: any;
|
|
39
|
-
type?: string;
|
|
40
|
-
}) => IRequestOptions;
|
|
41
|
-
initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
|
|
42
|
-
initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
|
|
43
|
-
}
|
|
44
|
-
export declare class Request extends RequestInit implements IRequest {
|
|
45
|
-
private request;
|
|
46
|
-
constructor(origin: any);
|
|
47
|
-
fetch: (_url: string, _opts: IRequestOptions) => Promise<any>;
|
|
48
|
-
http: (_url: string, _opts: IRequestOptions) => Promise<any>;
|
|
49
|
-
GET: (url?: IUrl, query?: IObject<any>, _?: IRequestBody | void, opts?: IRequestOptions) => any;
|
|
50
|
-
POST: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
51
|
-
PUT: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
52
|
-
DELETE: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
53
|
-
OPTIONS: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
54
|
-
HEAD: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
55
|
-
PATCH: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
56
|
-
}
|
|
57
|
-
declare const _default: {
|
|
58
|
-
Request: typeof Request;
|
|
59
|
-
};
|
|
60
|
-
export default _default;
|
|
1
|
+
import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./index.js";
|
|
2
|
+
declare class Interceptors implements IInterceptors {
|
|
3
|
+
private requestSuccess;
|
|
4
|
+
private responseSuccess;
|
|
5
|
+
private error;
|
|
6
|
+
use(type: "request" | "response" | "error", fn: Function): IInterceptors;
|
|
7
|
+
get reqFn(): Function;
|
|
8
|
+
get resFn(): Function;
|
|
9
|
+
get errFn(): Function;
|
|
10
|
+
}
|
|
11
|
+
declare abstract class RequestBase extends Interceptors implements IRequestBase {
|
|
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
|
+
fixOrigin: (fixStr: string) => string;
|
|
19
|
+
envDesc: () => IEnv;
|
|
20
|
+
errorFn: (reject: any) => (err: any) => any;
|
|
21
|
+
clearTimer: (opts: any) => any;
|
|
22
|
+
initAbort: (params: IRequestOptions) => IRequestOptions;
|
|
23
|
+
requestType: () => IRequestBaseFn;
|
|
24
|
+
getDataByType: (type: any, response: any) => any;
|
|
25
|
+
formatBodyString: (bodyString: string) => IObject<Function>;
|
|
26
|
+
}
|
|
27
|
+
declare abstract class RequestInit extends RequestBase implements IRequestInit {
|
|
28
|
+
constructor(origin: any);
|
|
29
|
+
abstract fetch(url: any, opts: any): Promise<void>;
|
|
30
|
+
abstract http(url: any, opts: any): Promise<void>;
|
|
31
|
+
initDefaultParams: (url: IUrl, { method, query, headers, body, timeout, controller, type, ...others }: {
|
|
32
|
+
[x: string]: any;
|
|
33
|
+
method?: string;
|
|
34
|
+
query?: {};
|
|
35
|
+
headers?: {};
|
|
36
|
+
body?: any;
|
|
37
|
+
timeout?: number;
|
|
38
|
+
controller?: any;
|
|
39
|
+
type?: string;
|
|
40
|
+
}) => IRequestOptions;
|
|
41
|
+
initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
|
|
42
|
+
initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
|
|
43
|
+
}
|
|
44
|
+
export declare class Request extends RequestInit implements IRequest {
|
|
45
|
+
private request;
|
|
46
|
+
constructor(origin: any);
|
|
47
|
+
fetch: (_url: string, _opts: IRequestOptions) => Promise<any>;
|
|
48
|
+
http: (_url: string, _opts: IRequestOptions) => Promise<any>;
|
|
49
|
+
GET: (url?: IUrl, query?: IObject<any>, _?: IRequestBody | void, opts?: IRequestOptions) => any;
|
|
50
|
+
POST: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
51
|
+
PUT: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
52
|
+
DELETE: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
53
|
+
OPTIONS: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
54
|
+
HEAD: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
55
|
+
PATCH: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
|
|
56
|
+
}
|
|
57
|
+
declare const _default: {
|
|
58
|
+
Request: typeof Request;
|
|
59
|
+
};
|
|
60
|
+
export default _default;
|