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.
Files changed (72) hide show
  1. package/dist/bundle/array.d.ts +10 -0
  2. package/dist/bundle/base.d.ts +14 -0
  3. package/dist/bundle/element.d.ts +6 -0
  4. package/dist/bundle/event.d.ts +14 -0
  5. package/dist/bundle/function.d.ts +12 -0
  6. package/dist/bundle/index.d.ts +51 -0
  7. package/dist/bundle/index.js +1023 -0
  8. package/dist/bundle/object.d.ts +30 -0
  9. package/dist/bundle/request.d.ts +60 -0
  10. package/dist/bundle/static.d.ts +16 -0
  11. package/dist/bundle/storage.d.ts +9 -0
  12. package/dist/bundle/types.d.ts +103 -0
  13. package/dist/cjs/array.d.ts +10 -10
  14. package/dist/cjs/array.js +19 -19
  15. package/dist/cjs/base.d.ts +14 -14
  16. package/dist/cjs/base.js +56 -56
  17. package/dist/cjs/element.d.ts +6 -6
  18. package/dist/cjs/element.js +16 -16
  19. package/dist/cjs/event.d.ts +14 -14
  20. package/dist/cjs/event.js +53 -53
  21. package/dist/cjs/function.d.ts +12 -12
  22. package/dist/cjs/function.js +66 -66
  23. package/dist/cjs/index.d.ts +51 -51
  24. package/dist/cjs/index.js +54 -54
  25. package/dist/cjs/object.d.ts +30 -30
  26. package/dist/cjs/object.js +190 -190
  27. package/dist/cjs/request.d.ts +60 -60
  28. package/dist/cjs/request.js +239 -239
  29. package/dist/cjs/static.d.ts +16 -16
  30. package/dist/cjs/static.js +18 -18
  31. package/dist/cjs/storage.d.ts +9 -9
  32. package/dist/cjs/storage.js +41 -41
  33. package/dist/cjs/types.d.ts +103 -103
  34. package/dist/cjs/types.js +2 -2
  35. package/dist/esm/array.d.ts +10 -10
  36. package/dist/esm/array.js +13 -13
  37. package/dist/esm/base.d.ts +14 -14
  38. package/dist/esm/base.js +48 -48
  39. package/dist/esm/element.d.ts +6 -6
  40. package/dist/esm/element.js +12 -12
  41. package/dist/esm/event.d.ts +14 -14
  42. package/dist/esm/event.js +45 -45
  43. package/dist/esm/function.d.ts +12 -12
  44. package/dist/esm/function.js +59 -59
  45. package/dist/esm/index.d.ts +51 -51
  46. package/dist/esm/index.js +35 -35
  47. package/dist/esm/object.d.ts +30 -30
  48. package/dist/esm/object.js +174 -174
  49. package/dist/esm/request.d.ts +60 -60
  50. package/dist/esm/request.js +236 -236
  51. package/dist/esm/static.d.ts +16 -16
  52. package/dist/esm/static.js +15 -15
  53. package/dist/esm/storage.d.ts +9 -9
  54. package/dist/esm/storage.js +35 -35
  55. package/dist/esm/types.d.ts +103 -103
  56. package/dist/esm/types.js +1 -1
  57. package/dist/umd/array.d.ts +10 -0
  58. package/dist/umd/base.d.ts +14 -0
  59. package/dist/umd/element.d.ts +6 -0
  60. package/dist/umd/event.d.ts +14 -0
  61. package/dist/umd/function.d.ts +12 -0
  62. package/dist/umd/index.d.ts +51 -0
  63. package/dist/umd/index.js +1024 -0
  64. package/dist/umd/object.d.ts +30 -0
  65. package/dist/umd/request.d.ts +60 -0
  66. package/dist/umd/static.d.ts +16 -0
  67. package/dist/umd/storage.d.ts +9 -0
  68. package/dist/umd/types.d.ts +103 -0
  69. package/package.json +12 -4
  70. package/pnpm-lock.yaml +279 -8
  71. package/rollup.config.js +35 -0
  72. package/tsconfig.umd.json +6 -0
@@ -1,239 +1,239 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __rest = (this && this.__rest) || function (s, e) {
29
- var t = {};
30
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
- t[p] = s[p];
32
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
- t[p[i]] = s[p[i]];
36
- }
37
- return t;
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.Request = void 0;
41
- var index_js_1 = require("./index.js");
42
- var httpRequest, httpsRequest, parse, CustomAbortController;
43
- if (typeof require !== "undefined") {
44
- CustomAbortController = require("abort-controller");
45
- httpRequest = require("http").request;
46
- httpsRequest = require("https").request;
47
- parse = require("url").parse;
48
- }
49
- else if (typeof AbortController !== "undefined") {
50
- CustomAbortController = AbortController;
51
- }
52
- else {
53
- CustomAbortController = function () {
54
- throw new Error('AbortController is not defined');
55
- };
56
- }
57
- var Interceptors = (function () {
58
- function Interceptors() {
59
- }
60
- Interceptors.prototype.use = function (type, fn) {
61
- switch (type) {
62
- case "request":
63
- this.requestSuccess = fn;
64
- break;
65
- case "response":
66
- this.responseSuccess = fn;
67
- break;
68
- case "error":
69
- this.error = fn;
70
- break;
71
- }
72
- return this;
73
- };
74
- Object.defineProperty(Interceptors.prototype, "reqFn", {
75
- get: function () {
76
- return this.requestSuccess;
77
- },
78
- enumerable: false,
79
- configurable: true
80
- });
81
- Object.defineProperty(Interceptors.prototype, "resFn", {
82
- get: function () {
83
- return this.responseSuccess;
84
- },
85
- enumerable: false,
86
- configurable: true
87
- });
88
- Object.defineProperty(Interceptors.prototype, "errFn", {
89
- get: function () {
90
- return this.error;
91
- },
92
- enumerable: false,
93
- configurable: true
94
- });
95
- return Interceptors;
96
- }());
97
- var RequestBase = (function (_super) {
98
- __extends(RequestBase, _super);
99
- function RequestBase(origin) {
100
- var _this = _super.call(this) || this;
101
- _this.chackUrl = function (url) {
102
- return url.startsWith('/');
103
- };
104
- _this.checkIsHttps = function (url) {
105
- return url.startsWith('https');
106
- };
107
- _this.fixOrigin = function (fixStr) {
108
- if (_this.chackUrl(fixStr))
109
- return _this.origin + fixStr;
110
- return fixStr;
111
- };
112
- _this.envDesc = function () {
113
- if (typeof Window !== "undefined") {
114
- return "Window";
115
- }
116
- return "Node";
117
- };
118
- _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); }; };
119
- _this.clearTimer = function (opts) { return !!opts.timer && (clearTimeout(opts.timer), opts.timer = null); };
120
- _this.initAbort = function (params) {
121
- var controller = params.controller, timer = params.timer, timeout = params.timeout;
122
- !!!timer && (params.timer = setTimeout(function () { return controller.abort(); }, timeout));
123
- return params;
124
- };
125
- _this.requestType = function () {
126
- switch (_this.envDesc()) {
127
- case "Window":
128
- return _this.fetch;
129
- case "Node":
130
- return _this.http;
131
- }
132
- };
133
- _this.getDataByType = function (type, response) {
134
- switch (type) {
135
- case "text":
136
- case "json":
137
- case "blob":
138
- case "formData":
139
- case "arrayBuffer":
140
- return response[type]();
141
- default:
142
- return response['json']();
143
- }
144
- };
145
- _this.formatBodyString = function (bodyString) {
146
- return {
147
- text: function () { return bodyString; },
148
- json: function () { var _a; return (_a = (0, index_js_1.stringToJson)(bodyString)) !== null && _a !== void 0 ? _a : bodyString; },
149
- blob: function () { return (0, index_js_1.stringToJson)(bodyString); },
150
- formData: function () { return (0, index_js_1.stringToJson)(bodyString); },
151
- arrayBuffer: function () { return (0, index_js_1.stringToJson)(bodyString); },
152
- };
153
- };
154
- _this.origin = origin !== null && origin !== void 0 ? origin : '';
155
- return _this;
156
- }
157
- return RequestBase;
158
- }(Interceptors));
159
- var RequestInit = (function (_super) {
160
- __extends(RequestInit, _super);
161
- function RequestInit(origin) {
162
- var _this = _super.call(this, origin) || this;
163
- _this.initDefaultParams = function (url, _a) {
164
- var _b, _c;
165
- var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new CustomAbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
166
- var __params = __assign({ url: url, method: method, query: query, headers: headers, body: method === "GET" ? null : (0, index_js_1.jsonToString)(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
167
- var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
168
- params.url = (0, index_js_1.urlJoin)(_this.fixOrigin(url), __params.query);
169
- return params;
170
- };
171
- _this.initFetchParams = function (url, opts) {
172
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
173
- return _temp;
174
- };
175
- _this.initHttpParams = function (url, opts) {
176
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
177
- var options = parse(_temp.url, true);
178
- return __assign(__assign({}, _temp), options);
179
- };
180
- return _this;
181
- }
182
- return RequestInit;
183
- }(RequestBase));
184
- var Request = (function (_super) {
185
- __extends(Request, _super);
186
- function Request(origin) {
187
- var _this = _super.call(this, origin) || this;
188
- _this.fetch = function (_url, _opts) {
189
- var _a = (0, index_js_1.defer)(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
190
- var _b = _this.initFetchParams(_url, _opts), url = _b.url, opts = __rest(_b, ["url"]);
191
- var signal = opts.signal;
192
- promise.finally(function () { return _this.clearTimer(opts); });
193
- signal.addEventListener('abort', function () { return _this.errorFn(reject); });
194
- fetch(url, opts).then(function (response) {
195
- if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) < 300) {
196
- return _this.getDataByType(opts.type, response);
197
- }
198
- return _this.errorFn(reject);
199
- }).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));
200
- return promise;
201
- };
202
- _this.http = function (_url, _opts) {
203
- var _a = (0, index_js_1.defer)(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
204
- var params = _this.initHttpParams(_url, _opts);
205
- var signal = params.signal, url = params.url;
206
- promise.finally(function () { return _this.clearTimer(params); });
207
- var request = _this.checkIsHttps(url) ? httpsRequest : httpRequest;
208
- var req = request(params, function (response) {
209
- if ((response === null || response === void 0 ? void 0 : response.statusCode) >= 200 && (response === null || response === void 0 ? void 0 : response.statusCode) < 300) {
210
- var data_1 = "";
211
- response.setEncoding('utf8');
212
- response.on('data', function (chunk) { return data_1 += chunk; });
213
- return response.on("end", function () {
214
- var _a, _b;
215
- var result = _this.getDataByType(params.type, _this.formatBodyString(data_1));
216
- resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, result)) !== null && _b !== void 0 ? _b : result);
217
- });
218
- }
219
- return _this.errorFn(reject)(response === null || response === void 0 ? void 0 : response.statusMessage);
220
- });
221
- signal.addEventListener('abort', function () { return _this.errorFn(reject)(req.destroy(new Error('request timeout'))); });
222
- req.on('error', _this.errorFn(reject));
223
- req.end();
224
- return promise;
225
- };
226
- _this.GET = function (url, query, _, opts) { return _this.request(url, __assign({ query: query, method: "GET" }, opts)); };
227
- _this.POST = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts)); };
228
- _this.PUT = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts)); };
229
- _this.DELETE = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts)); };
230
- _this.OPTIONS = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts)); };
231
- _this.HEAD = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts)); };
232
- _this.PATCH = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts)); };
233
- _this.request = _this.requestType();
234
- return _this;
235
- }
236
- return Request;
237
- }(RequestInit));
238
- exports.Request = Request;
239
- exports.default = { Request: Request };
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __rest = (this && this.__rest) || function (s, e) {
29
+ var t = {};
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
+ t[p] = s[p];
32
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
+ t[p[i]] = s[p[i]];
36
+ }
37
+ return t;
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.Request = void 0;
41
+ var index_js_1 = require("./index.js");
42
+ var httpRequest, httpsRequest, parse, CustomAbortController;
43
+ if (typeof require !== "undefined") {
44
+ CustomAbortController = require("abort-controller");
45
+ httpRequest = require("http").request;
46
+ httpsRequest = require("https").request;
47
+ parse = require("url").parse;
48
+ }
49
+ else if (typeof AbortController !== "undefined") {
50
+ CustomAbortController = AbortController;
51
+ }
52
+ else {
53
+ CustomAbortController = function () {
54
+ throw new Error('AbortController is not defined');
55
+ };
56
+ }
57
+ var Interceptors = (function () {
58
+ function Interceptors() {
59
+ }
60
+ Interceptors.prototype.use = function (type, fn) {
61
+ switch (type) {
62
+ case "request":
63
+ this.requestSuccess = fn;
64
+ break;
65
+ case "response":
66
+ this.responseSuccess = fn;
67
+ break;
68
+ case "error":
69
+ this.error = fn;
70
+ break;
71
+ }
72
+ return this;
73
+ };
74
+ Object.defineProperty(Interceptors.prototype, "reqFn", {
75
+ get: function () {
76
+ return this.requestSuccess;
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
81
+ Object.defineProperty(Interceptors.prototype, "resFn", {
82
+ get: function () {
83
+ return this.responseSuccess;
84
+ },
85
+ enumerable: false,
86
+ configurable: true
87
+ });
88
+ Object.defineProperty(Interceptors.prototype, "errFn", {
89
+ get: function () {
90
+ return this.error;
91
+ },
92
+ enumerable: false,
93
+ configurable: true
94
+ });
95
+ return Interceptors;
96
+ }());
97
+ var RequestBase = (function (_super) {
98
+ __extends(RequestBase, _super);
99
+ function RequestBase(origin) {
100
+ var _this = _super.call(this) || this;
101
+ _this.chackUrl = function (url) {
102
+ return url.startsWith('/');
103
+ };
104
+ _this.checkIsHttps = function (url) {
105
+ return url.startsWith('https');
106
+ };
107
+ _this.fixOrigin = function (fixStr) {
108
+ if (_this.chackUrl(fixStr))
109
+ return _this.origin + fixStr;
110
+ return fixStr;
111
+ };
112
+ _this.envDesc = function () {
113
+ if (typeof Window !== "undefined") {
114
+ return "Window";
115
+ }
116
+ return "Node";
117
+ };
118
+ _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); }; };
119
+ _this.clearTimer = function (opts) { return !!opts.timer && (clearTimeout(opts.timer), opts.timer = null); };
120
+ _this.initAbort = function (params) {
121
+ var controller = params.controller, timer = params.timer, timeout = params.timeout;
122
+ !!!timer && (params.timer = setTimeout(function () { return controller.abort(); }, timeout));
123
+ return params;
124
+ };
125
+ _this.requestType = function () {
126
+ switch (_this.envDesc()) {
127
+ case "Window":
128
+ return _this.fetch;
129
+ case "Node":
130
+ return _this.http;
131
+ }
132
+ };
133
+ _this.getDataByType = function (type, response) {
134
+ switch (type) {
135
+ case "text":
136
+ case "json":
137
+ case "blob":
138
+ case "formData":
139
+ case "arrayBuffer":
140
+ return response[type]();
141
+ default:
142
+ return response['json']();
143
+ }
144
+ };
145
+ _this.formatBodyString = function (bodyString) {
146
+ return {
147
+ text: function () { return bodyString; },
148
+ json: function () { var _a; return (_a = (0, index_js_1.stringToJson)(bodyString)) !== null && _a !== void 0 ? _a : bodyString; },
149
+ blob: function () { return (0, index_js_1.stringToJson)(bodyString); },
150
+ formData: function () { return (0, index_js_1.stringToJson)(bodyString); },
151
+ arrayBuffer: function () { return (0, index_js_1.stringToJson)(bodyString); },
152
+ };
153
+ };
154
+ _this.origin = origin !== null && origin !== void 0 ? origin : '';
155
+ return _this;
156
+ }
157
+ return RequestBase;
158
+ }(Interceptors));
159
+ var RequestInit = (function (_super) {
160
+ __extends(RequestInit, _super);
161
+ function RequestInit(origin) {
162
+ var _this = _super.call(this, origin) || this;
163
+ _this.initDefaultParams = function (url, _a) {
164
+ var _b, _c;
165
+ var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new CustomAbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
166
+ var __params = __assign({ url: url, method: method, query: query, headers: headers, body: method === "GET" ? null : (0, index_js_1.jsonToString)(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
167
+ var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
168
+ params.url = (0, index_js_1.urlJoin)(_this.fixOrigin(url), __params.query);
169
+ return params;
170
+ };
171
+ _this.initFetchParams = function (url, opts) {
172
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
173
+ return _temp;
174
+ };
175
+ _this.initHttpParams = function (url, opts) {
176
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
177
+ var options = parse(_temp.url, true);
178
+ return __assign(__assign({}, _temp), options);
179
+ };
180
+ return _this;
181
+ }
182
+ return RequestInit;
183
+ }(RequestBase));
184
+ var Request = (function (_super) {
185
+ __extends(Request, _super);
186
+ function Request(origin) {
187
+ var _this = _super.call(this, origin) || this;
188
+ _this.fetch = function (_url, _opts) {
189
+ var _a = (0, index_js_1.defer)(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
190
+ var _b = _this.initFetchParams(_url, _opts), url = _b.url, opts = __rest(_b, ["url"]);
191
+ var signal = opts.signal;
192
+ promise.finally(function () { return _this.clearTimer(opts); });
193
+ signal.addEventListener('abort', function () { return _this.errorFn(reject); });
194
+ fetch(url, opts).then(function (response) {
195
+ if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) < 300) {
196
+ return _this.getDataByType(opts.type, response);
197
+ }
198
+ return _this.errorFn(reject);
199
+ }).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));
200
+ return promise;
201
+ };
202
+ _this.http = function (_url, _opts) {
203
+ var _a = (0, index_js_1.defer)(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
204
+ var params = _this.initHttpParams(_url, _opts);
205
+ var signal = params.signal, url = params.url;
206
+ promise.finally(function () { return _this.clearTimer(params); });
207
+ var request = _this.checkIsHttps(url) ? httpsRequest : httpRequest;
208
+ var req = request(params, function (response) {
209
+ if ((response === null || response === void 0 ? void 0 : response.statusCode) >= 200 && (response === null || response === void 0 ? void 0 : response.statusCode) < 300) {
210
+ var data_1 = "";
211
+ response.setEncoding('utf8');
212
+ response.on('data', function (chunk) { return data_1 += chunk; });
213
+ return response.on("end", function () {
214
+ var _a, _b;
215
+ var result = _this.getDataByType(params.type, _this.formatBodyString(data_1));
216
+ resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, result)) !== null && _b !== void 0 ? _b : result);
217
+ });
218
+ }
219
+ return _this.errorFn(reject)(response === null || response === void 0 ? void 0 : response.statusMessage);
220
+ });
221
+ signal.addEventListener('abort', function () { return _this.errorFn(reject)(req.destroy(new Error('request timeout'))); });
222
+ req.on('error', _this.errorFn(reject));
223
+ req.end();
224
+ return promise;
225
+ };
226
+ _this.GET = function (url, query, _, opts) { return _this.request(url, __assign({ query: query, method: "GET" }, opts)); };
227
+ _this.POST = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts)); };
228
+ _this.PUT = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts)); };
229
+ _this.DELETE = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts)); };
230
+ _this.OPTIONS = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts)); };
231
+ _this.HEAD = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts)); };
232
+ _this.PATCH = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts)); };
233
+ _this.request = _this.requestType();
234
+ return _this;
235
+ }
236
+ return Request;
237
+ }(RequestInit));
238
+ exports.Request = Request;
239
+ exports.default = { Request: Request };
@@ -1,16 +1,16 @@
1
- export declare enum types {
2
- "[object Array]" = "array",
3
- "[object Object]" = "object",
4
- "[object Function]" = "function",
5
- "[object Set]" = "set",
6
- "[object Map]" = "map",
7
- "[object WeakMap]" = "weakMap",
8
- "[object WeakSet]" = "weakSet",
9
- "[object Date]" = "date",
10
- "[object RegExp]" = "regExp",
11
- "[object Math]" = "math"
12
- }
13
- declare const _default: {
14
- types: typeof types;
15
- };
16
- export default _default;
1
+ export declare enum types {
2
+ "[object Array]" = "array",
3
+ "[object Object]" = "object",
4
+ "[object Function]" = "function",
5
+ "[object Set]" = "set",
6
+ "[object Map]" = "map",
7
+ "[object WeakMap]" = "weakMap",
8
+ "[object WeakSet]" = "weakSet",
9
+ "[object Date]" = "date",
10
+ "[object RegExp]" = "regExp",
11
+ "[object Math]" = "math"
12
+ }
13
+ declare const _default: {
14
+ types: typeof types;
15
+ };
16
+ export default _default;
@@ -1,18 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.types = void 0;
4
- var types;
5
- (function (types) {
6
- types["[object Array]"] = "array";
7
- types["[object Object]"] = "object";
8
- types["[object Function]"] = "function";
9
- types["[object Set]"] = "set";
10
- types["[object Map]"] = "map";
11
- types["[object WeakMap]"] = "weakMap";
12
- types["[object WeakSet]"] = "weakSet";
13
- types["[object Date]"] = "date";
14
- types["[object RegExp]"] = "regExp";
15
- types["[object Math]"] = "math";
16
- })(types = exports.types || (exports.types = {}));
17
- ;
18
- exports.default = { types: types };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.types = void 0;
4
+ var types;
5
+ (function (types) {
6
+ types["[object Array]"] = "array";
7
+ types["[object Object]"] = "object";
8
+ types["[object Function]"] = "function";
9
+ types["[object Set]"] = "set";
10
+ types["[object Map]"] = "map";
11
+ types["[object WeakMap]"] = "weakMap";
12
+ types["[object WeakSet]"] = "weakSet";
13
+ types["[object Date]"] = "date";
14
+ types["[object RegExp]"] = "regExp";
15
+ types["[object Math]"] = "math";
16
+ })(types = exports.types || (exports.types = {}));
17
+ ;
18
+ exports.default = { types: types };
@@ -1,9 +1,9 @@
1
- export declare const setStorage: (key: string, val: any) => void;
2
- export declare const getStorage: (key: string) => any;
3
- export declare const clearStorage: (key: string) => void;
4
- declare const _default: {
5
- setStorage: (key: string, val: any) => void;
6
- getStorage: (key: string) => any;
7
- clearStorage: (key: string) => void;
8
- };
9
- export default _default;
1
+ export declare const setStorage: (key: string, val: any) => void;
2
+ export declare const getStorage: (key: string) => any;
3
+ export declare const clearStorage: (key: string) => void;
4
+ declare const _default: {
5
+ setStorage: (key: string, val: any) => void;
6
+ getStorage: (key: string) => any;
7
+ clearStorage: (key: string) => void;
8
+ };
9
+ export default _default;
@@ -1,41 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clearStorage = exports.getStorage = exports.setStorage = void 0;
4
- var setStorage = function (key, val) {
5
- try {
6
- localStorage.setItem(key, JSON.stringify(val));
7
- }
8
- catch (error) {
9
- console.error(error);
10
- }
11
- };
12
- exports.setStorage = setStorage;
13
- var getStorage = function (key) {
14
- try {
15
- var str = localStorage.getItem(key);
16
- if (str === null || str === undefined) {
17
- return null;
18
- }
19
- return JSON.parse(str);
20
- }
21
- catch (error) {
22
- console.error(error);
23
- return null;
24
- }
25
- };
26
- exports.getStorage = getStorage;
27
- var clearStorage = function (key) {
28
- try {
29
- key && localStorage.removeItem(key);
30
- !key && localStorage.clear();
31
- }
32
- catch (error) {
33
- console.error(error);
34
- }
35
- };
36
- exports.clearStorage = clearStorage;
37
- exports.default = {
38
- setStorage: exports.setStorage,
39
- getStorage: exports.getStorage,
40
- clearStorage: exports.clearStorage
41
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearStorage = exports.getStorage = exports.setStorage = void 0;
4
+ var setStorage = function (key, val) {
5
+ try {
6
+ localStorage.setItem(key, JSON.stringify(val));
7
+ }
8
+ catch (error) {
9
+ console.error(error);
10
+ }
11
+ };
12
+ exports.setStorage = setStorage;
13
+ var getStorage = function (key) {
14
+ try {
15
+ var str = localStorage.getItem(key);
16
+ if (str === null || str === undefined) {
17
+ return null;
18
+ }
19
+ return JSON.parse(str);
20
+ }
21
+ catch (error) {
22
+ console.error(error);
23
+ return null;
24
+ }
25
+ };
26
+ exports.getStorage = getStorage;
27
+ var clearStorage = function (key) {
28
+ try {
29
+ key && localStorage.removeItem(key);
30
+ !key && localStorage.clear();
31
+ }
32
+ catch (error) {
33
+ console.error(error);
34
+ }
35
+ };
36
+ exports.clearStorage = clearStorage;
37
+ exports.default = {
38
+ setStorage: exports.setStorage,
39
+ getStorage: exports.getStorage,
40
+ clearStorage: exports.clearStorage
41
+ };