utils-lib-js 1.0.5 → 1.0.6
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/array.js +14 -25
- package/dist/common/base.js +49 -56
- package/dist/common/element.js +13 -21
- package/dist/common/event.js +46 -43
- package/dist/common/function.js +60 -66
- package/dist/common/index.js +26 -29
- package/dist/common/object.js +175 -185
- package/dist/common/request.d.ts +36 -13
- package/dist/common/request.js +225 -221
- package/dist/common/static.js +17 -18
- package/dist/common/storage.js +36 -34
- package/dist/common/types.d.ts +24 -11
- package/dist/common/types.js +2 -3
- package/dist/esm/array.js +8 -18
- package/dist/esm/base.js +41 -47
- package/dist/esm/element.js +9 -16
- package/dist/esm/event.js +38 -34
- package/dist/esm/function.js +53 -58
- package/dist/esm/index.js +10 -10
- package/dist/esm/object.js +159 -168
- package/dist/esm/request.d.ts +21 -5
- package/dist/esm/request.js +199 -217
- package/dist/esm/static.js +14 -14
- package/dist/esm/storage.js +30 -27
- package/dist/esm/types.d.ts +8 -3
- package/dist/esm/types.js +1 -1
- package/package.json +11 -5
- package/index.html +0 -37
package/dist/esm/request.js
CHANGED
|
@@ -1,217 +1,199 @@
|
|
|
1
|
-
var __extends = this && this.__extends || function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
d.__proto__ = b;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
case "
|
|
46
|
-
this.
|
|
47
|
-
break;
|
|
48
|
-
case "
|
|
49
|
-
this.
|
|
50
|
-
break;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
_this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
case "
|
|
130
|
-
case "
|
|
131
|
-
case "
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return response[
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return
|
|
181
|
-
};
|
|
182
|
-
_this.
|
|
183
|
-
if (query === void 0) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
return _this.request(url, __assign({ query: query, method: "
|
|
193
|
-
};
|
|
194
|
-
_this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
_this.DELETE = function (url, query, body, opts) {
|
|
201
|
-
if (query === void 0) {
|
|
202
|
-
query = {};
|
|
203
|
-
}
|
|
204
|
-
return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts));
|
|
205
|
-
};
|
|
206
|
-
_this.OPTION = function (url, query, body, opts) {
|
|
207
|
-
if (query === void 0) {
|
|
208
|
-
query = {};
|
|
209
|
-
}
|
|
210
|
-
return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts));
|
|
211
|
-
};
|
|
212
|
-
_this.request = _this.requestType();
|
|
213
|
-
return _this;
|
|
214
|
-
}
|
|
215
|
-
return Request;
|
|
216
|
-
}(RequestBase);
|
|
217
|
-
export { Request };
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
};
|
|
38
|
+
import { urlJoin, defer, jsonToString } from "./index.js";
|
|
39
|
+
import { request } from "node:http";
|
|
40
|
+
var Interceptors = (function () {
|
|
41
|
+
function Interceptors() {
|
|
42
|
+
}
|
|
43
|
+
Interceptors.prototype.use = function (type, fn) {
|
|
44
|
+
switch (type) {
|
|
45
|
+
case "request":
|
|
46
|
+
this.requestSuccess = fn;
|
|
47
|
+
break;
|
|
48
|
+
case "response":
|
|
49
|
+
this.responseSuccess = fn;
|
|
50
|
+
break;
|
|
51
|
+
case "error":
|
|
52
|
+
this.error = fn;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(Interceptors.prototype, "reqFn", {
|
|
58
|
+
get: function () {
|
|
59
|
+
return this.requestSuccess;
|
|
60
|
+
},
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: true
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(Interceptors.prototype, "resFn", {
|
|
65
|
+
get: function () {
|
|
66
|
+
return this.responseSuccess;
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(Interceptors.prototype, "errFn", {
|
|
72
|
+
get: function () {
|
|
73
|
+
return this.error;
|
|
74
|
+
},
|
|
75
|
+
enumerable: false,
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
return Interceptors;
|
|
79
|
+
}());
|
|
80
|
+
export { Interceptors };
|
|
81
|
+
var RequestBase = (function (_super) {
|
|
82
|
+
__extends(RequestBase, _super);
|
|
83
|
+
function RequestBase(origin) {
|
|
84
|
+
var _this = _super.call(this) || this;
|
|
85
|
+
_this.chackUrl = function (url) {
|
|
86
|
+
return url.startsWith('/');
|
|
87
|
+
};
|
|
88
|
+
_this.fixOrigin = function (fixStr) {
|
|
89
|
+
if (_this.chackUrl(fixStr))
|
|
90
|
+
return _this.origin + fixStr;
|
|
91
|
+
return fixStr;
|
|
92
|
+
};
|
|
93
|
+
_this.envDesc = function () {
|
|
94
|
+
if (typeof Window !== "undefined") {
|
|
95
|
+
return "Window";
|
|
96
|
+
}
|
|
97
|
+
return "Node";
|
|
98
|
+
};
|
|
99
|
+
_this.errorFn = function (reject) { return function (err) { var _a, _b; return reject((_b = (_a = _this.errFn) === null || _a === void 0 ? void 0 : _a.call(_this, err)) !== null && _b !== void 0 ? _b : err); }; };
|
|
100
|
+
_this.clearTimer = function (opts) { return !!opts.timer && (clearTimeout(opts.timer), opts.timer = null); };
|
|
101
|
+
_this.requestType = function () {
|
|
102
|
+
switch (_this.envDesc()) {
|
|
103
|
+
case "Window":
|
|
104
|
+
return _this.fetch;
|
|
105
|
+
case "Node":
|
|
106
|
+
return _this.http;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
_this.initDefaultParams = function (url, _a) {
|
|
110
|
+
var _b = _a.method, method = _b === void 0 ? "GET" : _b, _c = _a.query, query = _c === void 0 ? {} : _c, _d = _a.headers, headers = _d === void 0 ? {} : _d, _e = _a.body, body = _e === void 0 ? null : _e, _f = _a.timeout, timeout = _f === void 0 ? 30 * 1000 : _f, _g = _a.controller, controller = _g === void 0 ? new AbortController() : _g, _h = _a.type, type = _h === void 0 ? "json" : _h, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
|
|
111
|
+
return (__assign({ url: urlJoin(_this.fixOrigin(url), query), method: method, headers: headers, body: method === "GET" ? null : jsonToString(body), timeout: timeout, signal: controller.signal, controller: controller, type: type, timer: null }, others));
|
|
112
|
+
};
|
|
113
|
+
_this.initFetchParams = function (url, opts) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
var params = _this.initDefaultParams(url, opts);
|
|
116
|
+
var controller = params.controller, timer = params.timer, timeout = params.timeout;
|
|
117
|
+
!!!timer && (params.timer = setTimeout(function () { return controller.abort(); }, timeout));
|
|
118
|
+
return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, params)) !== null && _b !== void 0 ? _b : params;
|
|
119
|
+
};
|
|
120
|
+
_this.initHttpParams = function (url, opts) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
var params = _this.initDefaultParams(url, opts);
|
|
123
|
+
return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, params)) !== null && _b !== void 0 ? _b : params;
|
|
124
|
+
};
|
|
125
|
+
_this.getDataByType = function (type, response) {
|
|
126
|
+
switch (type) {
|
|
127
|
+
case "text":
|
|
128
|
+
case "json":
|
|
129
|
+
case "blob":
|
|
130
|
+
case "formData":
|
|
131
|
+
case "arrayBuffer":
|
|
132
|
+
return response[type]();
|
|
133
|
+
default:
|
|
134
|
+
return response['json']();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
_this.origin = origin !== null && origin !== void 0 ? origin : '';
|
|
138
|
+
return _this;
|
|
139
|
+
}
|
|
140
|
+
return RequestBase;
|
|
141
|
+
}(Interceptors));
|
|
142
|
+
export { RequestBase };
|
|
143
|
+
var Request = (function (_super) {
|
|
144
|
+
__extends(Request, _super);
|
|
145
|
+
function Request(origin) {
|
|
146
|
+
var _this = _super.call(this, origin) || this;
|
|
147
|
+
_this.fetch = function (_url, _opts) {
|
|
148
|
+
var _a = defer(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
|
|
149
|
+
var _b = _this.initFetchParams(_url, _opts), url = _b.url, opts = __rest(_b, ["url"]);
|
|
150
|
+
var signal = opts.signal;
|
|
151
|
+
signal.addEventListener('abort', _this.errorFn(reject));
|
|
152
|
+
fetch(url, opts).then(function (response) {
|
|
153
|
+
if (response.status >= 200 && response.status < 300) {
|
|
154
|
+
return _this.getDataByType(opts.type, response);
|
|
155
|
+
}
|
|
156
|
+
return _this.errorFn(reject);
|
|
157
|
+
}).then(function (res) { var _a, _b; return resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, res)) !== null && _b !== void 0 ? _b : res); }).catch(_this.errorFn(reject)).finally(function () { return _this.clearTimer(opts); });
|
|
158
|
+
return promise;
|
|
159
|
+
};
|
|
160
|
+
_this.http = function (_url, _opts) {
|
|
161
|
+
var _a = defer(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
|
|
162
|
+
var _b = _this.initFetchParams(_url, _opts), url = _b.url, opts = __rest(_b, ["url"]);
|
|
163
|
+
request(url, opts, resolve);
|
|
164
|
+
return promise;
|
|
165
|
+
};
|
|
166
|
+
_this.GET = function (url, query, _, opts) {
|
|
167
|
+
if (query === void 0) { query = {}; }
|
|
168
|
+
return _this.request(url, __assign({ query: query, method: "GET" }, opts));
|
|
169
|
+
};
|
|
170
|
+
_this.POST = function (url, query, body, opts) {
|
|
171
|
+
if (query === void 0) { query = {}; }
|
|
172
|
+
return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts));
|
|
173
|
+
};
|
|
174
|
+
_this.PUT = function (url, query, body, opts) {
|
|
175
|
+
if (query === void 0) { query = {}; }
|
|
176
|
+
return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts));
|
|
177
|
+
};
|
|
178
|
+
_this.DELETE = function (url, query, body, opts) {
|
|
179
|
+
if (query === void 0) { query = {}; }
|
|
180
|
+
return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts));
|
|
181
|
+
};
|
|
182
|
+
_this.OPTIONS = function (url, query, body, opts) {
|
|
183
|
+
if (query === void 0) { query = {}; }
|
|
184
|
+
return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts));
|
|
185
|
+
};
|
|
186
|
+
_this.HEAD = function (url, query, body, opts) {
|
|
187
|
+
if (query === void 0) { query = {}; }
|
|
188
|
+
return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts));
|
|
189
|
+
};
|
|
190
|
+
_this.PATCH = function (url, query, body, opts) {
|
|
191
|
+
if (query === void 0) { query = {}; }
|
|
192
|
+
return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts));
|
|
193
|
+
};
|
|
194
|
+
_this.request = _this.requestType();
|
|
195
|
+
return _this;
|
|
196
|
+
}
|
|
197
|
+
return Request;
|
|
198
|
+
}(RequestBase));
|
|
199
|
+
export { Request };
|
package/dist/esm/static.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export var types;
|
|
2
|
-
(function (types) {
|
|
3
|
-
types["[object Array]"] = "array";
|
|
4
|
-
types["[object Object]"] = "object";
|
|
5
|
-
types["[object Function]"] = "function";
|
|
6
|
-
types["[object Set]"] = "set";
|
|
7
|
-
types["[object Map]"] = "map";
|
|
8
|
-
types["[object WeakMap]"] = "weakMap";
|
|
9
|
-
types["[object WeakSet]"] = "weakSet";
|
|
10
|
-
types["[object Date]"] = "date";
|
|
11
|
-
types["[object RegExp]"] = "regExp";
|
|
12
|
-
types["[object Math]"] = "math";
|
|
13
|
-
})(types || (types = {}));
|
|
14
|
-
;
|
|
1
|
+
export var types;
|
|
2
|
+
(function (types) {
|
|
3
|
+
types["[object Array]"] = "array";
|
|
4
|
+
types["[object Object]"] = "object";
|
|
5
|
+
types["[object Function]"] = "function";
|
|
6
|
+
types["[object Set]"] = "set";
|
|
7
|
+
types["[object Map]"] = "map";
|
|
8
|
+
types["[object WeakMap]"] = "weakMap";
|
|
9
|
+
types["[object WeakSet]"] = "weakSet";
|
|
10
|
+
types["[object Date]"] = "date";
|
|
11
|
+
types["[object RegExp]"] = "regExp";
|
|
12
|
+
types["[object Math]"] = "math";
|
|
13
|
+
})(types || (types = {}));
|
|
14
|
+
;
|
package/dist/esm/storage.js
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
export var setStorage = function (key, val) {
|
|
2
|
-
try {
|
|
3
|
-
localStorage.setItem(key, JSON.stringify(val));
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
1
|
+
export var setStorage = function (key, val) {
|
|
2
|
+
try {
|
|
3
|
+
localStorage.setItem(key, JSON.stringify(val));
|
|
4
|
+
}
|
|
5
|
+
catch (error) {
|
|
6
|
+
console.error(error);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export var getStorage = function (key) {
|
|
10
|
+
try {
|
|
11
|
+
var str = localStorage.getItem(key);
|
|
12
|
+
if (str === null || str === undefined) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(str);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error(error);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export var clearStorage = function (key) {
|
|
23
|
+
try {
|
|
24
|
+
key && localStorage.removeItem(key);
|
|
25
|
+
!key && localStorage.clear();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error(error);
|
|
29
|
+
}
|
|
30
|
+
};
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare type IUrlSplit = (url: string) => IObject<any>;
|
|
|
16
16
|
export declare type IUrlJoin = (url: string, query: object) => string;
|
|
17
17
|
export declare type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
|
|
18
18
|
export declare type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
|
|
19
|
-
export declare type IGetValue = <T
|
|
19
|
+
export declare type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue?: any) => U;
|
|
20
20
|
export declare type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IObject<T>;
|
|
21
21
|
export declare type IMixIn = <U extends IObject<any>>(target?: U, source?: IObject<any>, overwrite?: boolean) => U;
|
|
22
22
|
export declare type IEnumInversion = (target: IObject<string>) => IObject<string>;
|
|
@@ -58,8 +58,9 @@ export declare type IRequestOptions = {
|
|
|
58
58
|
query?: IRequestParams<IObject<any>>;
|
|
59
59
|
body?: IRequestBody;
|
|
60
60
|
headers?: IRequestHeaders;
|
|
61
|
-
|
|
61
|
+
controller?: AbortController;
|
|
62
62
|
timeout?: number;
|
|
63
|
+
timer?: number | unknown | null;
|
|
63
64
|
[key: string]: any;
|
|
64
65
|
};
|
|
65
66
|
export declare type IInterceptors = {
|
|
@@ -75,7 +76,9 @@ export declare type IRequestBase = {
|
|
|
75
76
|
chackUrl: (url: string) => boolean;
|
|
76
77
|
fetch: (url: string, opts: IRequestOptions) => Promise<any>;
|
|
77
78
|
http: (url: string, opts: IRequestOptions) => Promise<any>;
|
|
79
|
+
initDefaultParams: (url: string, opts: IRequestOptions) => any;
|
|
78
80
|
initFetchParams: (url: string, opts: IRequestOptions) => any;
|
|
81
|
+
initHttpParams: (url: string, opts: IRequestOptions) => any;
|
|
79
82
|
getDataByType: (type: IDataType, response: Response) => Promise<any>;
|
|
80
83
|
};
|
|
81
84
|
export declare type IRequest = {
|
|
@@ -84,6 +87,8 @@ export declare type IRequest = {
|
|
|
84
87
|
POST: IRequestFn;
|
|
85
88
|
DELETE: IRequestFn;
|
|
86
89
|
PUT: IRequestFn;
|
|
87
|
-
|
|
90
|
+
OPTIONS: IRequestFn;
|
|
91
|
+
HEAD: IRequestFn;
|
|
92
|
+
PATCH: IRequestFn;
|
|
88
93
|
} & IRequestBase;
|
|
89
94
|
export {};
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utils-lib-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "JavaScript工具函数,封装的一些常用的js函数",
|
|
5
5
|
"main": "./dist/common/index.js",
|
|
6
6
|
"types": "./dist/common/index.d.ts",
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
"require": "./dist/common/index.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"debug": "start cmd /k pnpm run build:hot
|
|
14
|
-
"node
|
|
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 ./example/server.js",
|
|
15
16
|
"build:hot:esm": "tsc -p tsconfig.es.json -w",
|
|
16
|
-
"build:hot": "tsc -p tsconfig.json -w",
|
|
17
|
+
"build:hot:node": "tsc -p tsconfig.json -w",
|
|
17
18
|
"build": "pnpm run tsc:build && pnpm run babel:mjs && pnpm run babel:cjs",
|
|
18
19
|
"tsc:build": "rm -fr dist && tsc -p tsconfig.json && tsc -p tsconfig.es.json",
|
|
19
20
|
"publish": "pnpm run build && pnpm publish",
|
|
@@ -25,13 +26,18 @@
|
|
|
25
26
|
"type": "git",
|
|
26
27
|
"url": "https://gitee.com/DieHunter/utils-lib-js.git"
|
|
27
28
|
},
|
|
28
|
-
"keywords": [
|
|
29
|
+
"keywords": [
|
|
30
|
+
"utils",
|
|
31
|
+
"tools",
|
|
32
|
+
"lib"
|
|
33
|
+
],
|
|
29
34
|
"author": "",
|
|
30
35
|
"license": "ISC",
|
|
31
36
|
"dependencies": {
|
|
32
37
|
"event-message-center": "^1.0.16"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
40
|
+
"@types/node": "^18.7.1",
|
|
35
41
|
"babel-cli": "^6.26.0"
|
|
36
42
|
}
|
|
37
43
|
}
|
package/index.html
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Document</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<script type="module">
|
|
11
|
-
import { Request } from "./dist/esm/request.js";
|
|
12
|
-
const resource = new Request("http://127.0.0.1:1024");
|
|
13
|
-
resource
|
|
14
|
-
.use("request", (params) => {
|
|
15
|
-
return params;
|
|
16
|
-
})
|
|
17
|
-
.use("response", (params) => {
|
|
18
|
-
return params;
|
|
19
|
-
})
|
|
20
|
-
.use("error", (error) => {
|
|
21
|
-
console.log(error)
|
|
22
|
-
return error;
|
|
23
|
-
});
|
|
24
|
-
resource
|
|
25
|
-
.GET(
|
|
26
|
-
"/getList",
|
|
27
|
-
{
|
|
28
|
-
name: "hello",
|
|
29
|
-
age: 22,
|
|
30
|
-
},
|
|
31
|
-
{},
|
|
32
|
-
{}
|
|
33
|
-
)
|
|
34
|
-
.then((res) => console.log(res));
|
|
35
|
-
</script>
|
|
36
|
-
</body>
|
|
37
|
-
</html>
|