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