utils-lib-js 1.0.6 → 1.0.7

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,199 +1,277 @@
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 };
1
+ var __extends = this && this.__extends || function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
4
+ d.__proto__ = b;
5
+ } || function (d, b) {
6
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
7
+ };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() {
14
+ this.constructor = d;
15
+ }
16
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17
+ };
18
+ }();
19
+ var __assign = this && this.__assign || function () {
20
+ __assign = Object.assign || function (t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
24
+ }
25
+ return t;
26
+ };
27
+ return __assign.apply(this, arguments);
28
+ };
29
+ var __rest = this && this.__rest || function (s, e) {
30
+ var t = {};
31
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
32
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") 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])) t[p[i]] = s[p[i]];
34
+ }
35
+ return t;
36
+ };
37
+ import { urlJoin, defer, jsonToString } from "./index.js";
38
+ import { request } from "node:http";
39
+ import { parse } from "node:url";
40
+ var Interceptors = function () {
41
+ function Interceptors() {}
42
+ Interceptors.prototype.use = function (type, fn) {
43
+ switch (type) {
44
+ case "request":
45
+ this.requestSuccess = fn;
46
+ break;
47
+ case "response":
48
+ this.responseSuccess = fn;
49
+ break;
50
+ case "error":
51
+ this.error = fn;
52
+ break;
53
+ }
54
+ return this;
55
+ };
56
+ Object.defineProperty(Interceptors.prototype, "reqFn", {
57
+ get: function () {
58
+ return this.requestSuccess;
59
+ },
60
+ enumerable: false,
61
+ configurable: true
62
+ });
63
+ Object.defineProperty(Interceptors.prototype, "resFn", {
64
+ get: function () {
65
+ return this.responseSuccess;
66
+ },
67
+ enumerable: false,
68
+ configurable: true
69
+ });
70
+ Object.defineProperty(Interceptors.prototype, "errFn", {
71
+ get: function () {
72
+ return this.error;
73
+ },
74
+ enumerable: false,
75
+ configurable: true
76
+ });
77
+ return Interceptors;
78
+ }();
79
+ var RequestBase = function (_super) {
80
+ __extends(RequestBase, _super);
81
+ function RequestBase(origin) {
82
+ var _this = _super.call(this) || this;
83
+ _this.chackUrl = function (url) {
84
+ return url.startsWith('/');
85
+ };
86
+ _this.fixOrigin = function (fixStr) {
87
+ if (_this.chackUrl(fixStr)) return _this.origin + fixStr;
88
+ return fixStr;
89
+ };
90
+ _this.envDesc = function () {
91
+ if (typeof Window !== "undefined") {
92
+ return "Window";
93
+ }
94
+ return "Node";
95
+ };
96
+ _this.errorFn = function (reject) {
97
+ return function (err) {
98
+ 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);
99
+ };
100
+ };
101
+ _this.clearTimer = function (opts) {
102
+ return !!opts.timer && (clearTimeout(opts.timer), opts.timer = null);
103
+ };
104
+ _this.initAbort = function (params) {
105
+ var controller = params.controller,
106
+ timer = params.timer,
107
+ timeout = params.timeout;
108
+ !!!timer && (params.timer = setTimeout(function () {
109
+ return controller.abort();
110
+ }, timeout));
111
+ return params;
112
+ };
113
+ _this.requestType = function () {
114
+ switch (_this.envDesc()) {
115
+ case "Window":
116
+ return _this.fetch;
117
+ case "Node":
118
+ return _this.http;
119
+ }
120
+ };
121
+ _this.getDataByType = function (type, response) {
122
+ switch (type) {
123
+ case "text":
124
+ case "json":
125
+ case "blob":
126
+ case "formData":
127
+ case "arrayBuffer":
128
+ return response[type]();
129
+ default:
130
+ return response['json']();
131
+ }
132
+ };
133
+ _this.origin = origin !== null && origin !== void 0 ? origin : '';
134
+ return _this;
135
+ }
136
+ return RequestBase;
137
+ }(Interceptors);
138
+ var RequestInit = function (_super) {
139
+ __extends(RequestInit, _super);
140
+ function RequestInit(origin) {
141
+ var _this = _super.call(this, origin) || this;
142
+ _this.initDefaultParams = function (url, _a) {
143
+ var _b = _a.method,
144
+ method = _b === void 0 ? "GET" : _b,
145
+ _c = _a.query,
146
+ query = _c === void 0 ? {} : _c,
147
+ _d = _a.headers,
148
+ headers = _d === void 0 ? {} : _d,
149
+ _e = _a.body,
150
+ body = _e === void 0 ? null : _e,
151
+ _f = _a.timeout,
152
+ timeout = _f === void 0 ? 30 * 1000 : _f,
153
+ _g = _a.controller,
154
+ controller = _g === void 0 ? new AbortController() : _g,
155
+ _h = _a.type,
156
+ type = _h === void 0 ? "json" : _h,
157
+ others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
158
+ 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);
159
+ };
160
+ _this.initFetchParams = function (url, opts) {
161
+ var _a, _b;
162
+ var params = _this.initAbort(_this.initDefaultParams(url, opts));
163
+ return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, params)) !== null && _b !== void 0 ? _b : params;
164
+ };
165
+ _this.initHttpParams = function (url, opts) {
166
+ var _a, _b;
167
+ var params = _this.initAbort(_this.initDefaultParams(url, opts));
168
+ var options = parse(params.url, true);
169
+ return (_b = (_a = _this.reqFn) === null || _a === void 0 ? void 0 : _a.call(_this, __assign(__assign({}, params), options))) !== null && _b !== void 0 ? _b : params;
170
+ };
171
+ return _this;
172
+ }
173
+ return RequestInit;
174
+ }(RequestBase);
175
+ var Request = function (_super) {
176
+ __extends(Request, _super);
177
+ function Request(origin) {
178
+ var _this = _super.call(this, origin) || this;
179
+ _this.fetch = function (_url, _opts) {
180
+ var _a = defer(),
181
+ promise = _a.promise,
182
+ resolve = _a.resolve,
183
+ reject = _a.reject;
184
+ var _b = _this.initFetchParams(_url, _opts),
185
+ url = _b.url,
186
+ opts = __rest(_b, ["url"]);
187
+ var signal = opts.signal;
188
+ signal.addEventListener('abort', function () {
189
+ return _this.errorFn(reject);
190
+ });
191
+ fetch(url, opts).then(function (response) {
192
+ if (response.status >= 200 && response.status < 300) {
193
+ return _this.getDataByType(opts.type, response);
194
+ }
195
+ return _this.errorFn(reject);
196
+ }).then(function (res) {
197
+ 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);
198
+ }).catch(_this.errorFn(reject)).finally(function () {
199
+ return _this.clearTimer(opts);
200
+ });
201
+ return promise;
202
+ };
203
+ _this.http = function (_url, _opts) {
204
+ var _a = defer(),
205
+ promise = _a.promise,
206
+ resolve = _a.resolve,
207
+ reject = _a.reject;
208
+ var params = _this.initHttpParams(_url, _opts);
209
+ var signal = params.signal;
210
+ var req = request(params, function (response) {
211
+ if (response.statusCode >= 200 && response.statusCode < 300) {
212
+ var data_1 = "";
213
+ response.setEncoding('utf8');
214
+ response.on('data', function (chunk) {
215
+ return data_1 += chunk;
216
+ });
217
+ return response.on("end", function () {
218
+ var _a, _b;return resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, data_1)) !== null && _b !== void 0 ? _b : data_1);
219
+ });
220
+ }
221
+ return _this.errorFn(reject)(response === null || response === void 0 ? void 0 : response.statusMessage);
222
+ });
223
+ signal.addEventListener('abort', function () {
224
+ return _this.errorFn(reject)(req.destroy(new Error('request timeout')));
225
+ });
226
+ req.on('error', _this.errorFn(reject));
227
+ req.end();
228
+ return promise;
229
+ };
230
+ _this.GET = function (url, query, _, opts) {
231
+ if (query === void 0) {
232
+ query = {};
233
+ }
234
+ return _this.request(url, __assign({ query: query, method: "GET" }, opts));
235
+ };
236
+ _this.POST = function (url, query, body, opts) {
237
+ if (query === void 0) {
238
+ query = {};
239
+ }
240
+ return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts));
241
+ };
242
+ _this.PUT = function (url, query, body, opts) {
243
+ if (query === void 0) {
244
+ query = {};
245
+ }
246
+ return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts));
247
+ };
248
+ _this.DELETE = function (url, query, body, opts) {
249
+ if (query === void 0) {
250
+ query = {};
251
+ }
252
+ return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts));
253
+ };
254
+ _this.OPTIONS = function (url, query, body, opts) {
255
+ if (query === void 0) {
256
+ query = {};
257
+ }
258
+ return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts));
259
+ };
260
+ _this.HEAD = function (url, query, body, opts) {
261
+ if (query === void 0) {
262
+ query = {};
263
+ }
264
+ return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts));
265
+ };
266
+ _this.PATCH = function (url, query, body, opts) {
267
+ if (query === void 0) {
268
+ query = {};
269
+ }
270
+ return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts));
271
+ };
272
+ _this.request = _this.requestType();
273
+ return _this;
274
+ }
275
+ return Request;
276
+ }(RequestInit);
277
+ export { Request };
@@ -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
+ ;
@@ -1,30 +1,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
- };
1
+ export var setStorage = function (key, val) {
2
+ try {
3
+ localStorage.setItem(key, JSON.stringify(val));
4
+ } catch (error) {
5
+ console.error(error);
6
+ }
7
+ };
8
+ export var getStorage = function (key) {
9
+ try {
10
+ var str = localStorage.getItem(key);
11
+ if (str === null || str === undefined) {
12
+ return null;
13
+ }
14
+ return JSON.parse(str);
15
+ } catch (error) {
16
+ console.error(error);
17
+ return null;
18
+ }
19
+ };
20
+ export var clearStorage = function (key) {
21
+ try {
22
+ key && localStorage.removeItem(key);
23
+ !key && localStorage.clear();
24
+ } catch (error) {
25
+ console.error(error);
26
+ }
27
+ };
@@ -48,11 +48,14 @@ export declare type IStopDefault = (e: Event) => void;
48
48
  export declare type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
49
49
  export declare type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
50
50
  export declare type IRequestParams<T> = T | IObject<any> | null;
51
+ export declare type IUrl = string;
52
+ export declare type IEnv = 'Window' | 'Node';
51
53
  export declare type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer";
52
54
  export declare type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION";
53
55
  export declare type IRequestBody = IRequestParams<BodyInit>;
54
56
  export declare type IRequestHeaders = IRequestParams<HeadersInit>;
55
- export declare type IRequestFn = (url: string, params: IObject<any>, body: IRequestBody, opts: IRequestOptions) => Promise<any>;
57
+ export declare type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
58
+ export declare type IRequestFn = (url: IUrl, params: IObject<any>, body: IRequestBody, opts: IRequestOptions) => Promise<any>;
56
59
  export declare type IRequestOptions = {
57
60
  method?: IRequestMethods;
58
61
  query?: IRequestParams<IObject<any>>;
@@ -70,19 +73,24 @@ export declare type IInterceptors = {
70
73
  get errFn(): Function;
71
74
  };
72
75
  export declare type IRequestBase = {
73
- origin: string;
76
+ readonly origin: string;
77
+ chackUrl: (url: IUrl) => boolean;
78
+ envDesc: () => IEnv;
79
+ errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
80
+ clearTimer: (opts: IRequestOptions) => void;
81
+ initAbort: <T = IRequestOptions>(opts: T) => T;
82
+ requestType: () => IRequestBaseFn;
74
83
  fixOrigin: (fixStr: string) => string;
75
- envDesc: () => "Window" | "Node";
76
- chackUrl: (url: string) => boolean;
77
- fetch: (url: string, opts: IRequestOptions) => Promise<any>;
78
- http: (url: string, opts: IRequestOptions) => Promise<any>;
79
- initDefaultParams: (url: string, opts: IRequestOptions) => any;
80
- initFetchParams: (url: string, opts: IRequestOptions) => any;
81
- initHttpParams: (url: string, opts: IRequestOptions) => any;
84
+ fetch: IRequestBaseFn;
85
+ http: IRequestBaseFn;
82
86
  getDataByType: (type: IDataType, response: Response) => Promise<any>;
83
87
  };
88
+ export declare type IRequestInit = {
89
+ initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
90
+ initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
91
+ initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
92
+ };
84
93
  export declare type IRequest = {
85
- request: Function;
86
94
  GET: IRequestFn;
87
95
  POST: IRequestFn;
88
96
  DELETE: IRequestFn;
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.6",
3
+ "version": "1.0.7",
4
4
  "description": "JavaScript工具函数,封装的一些常用的js函数",
5
5
  "main": "./dist/common/index.js",
6
6
  "types": "./dist/common/index.d.ts",