@nsnanocat/util 0.0.0-preview-ce381a0 → 0.0.0-preview-1422296
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/getStorage.mjs +64 -47
- package/dist/index.d.ts +3 -11
- package/dist/index.js +3 -11
- package/dist/lib/app.mjs +25 -9
- package/dist/lib/done.mjs +58 -48
- package/dist/lib/environment.mjs +15 -16
- package/dist/lib/index.d.mts +5 -0
- package/dist/lib/index.mjs +5 -5
- package/dist/lib/notification.mjs +50 -29
- package/dist/lib/runScript.mjs +27 -18
- package/dist/lib/time.mjs +17 -4
- package/dist/lib/wait.mjs +5 -3
- package/dist/polyfill/Console.mjs +171 -145
- package/dist/polyfill/Lodash.mjs +39 -29
- package/dist/polyfill/StatusTexts.mjs +2 -3
- package/dist/polyfill/Storage.d.mts +12 -0
- package/dist/polyfill/Storage.mjs +167 -173
- package/dist/polyfill/fetch-node.d.mts +3 -0
- package/dist/polyfill/fetch-node.mjs +2 -2
- package/dist/polyfill/fetch.mjs +115 -79
- package/dist/polyfill/index.d.mts +5 -0
- package/dist/polyfill/index.mjs +5 -5
- package/package.json +4 -4
- package/dist/lib/index.d.ts +0 -5
- package/dist/polyfill/Storage.d.ts +0 -8
- package/dist/polyfill/fetch-node.d.ts +0 -1
- package/dist/polyfill/index.d.ts +0 -5
- /package/dist/{getStorage.d.ts → getStorage.d.mts} +0 -0
- /package/dist/lib/{app.d.ts → app.d.mts} +0 -0
- /package/dist/lib/{done.d.ts → done.d.mts} +0 -0
- /package/dist/lib/{environment.d.ts → environment.d.mts} +0 -0
- /package/dist/lib/{notification.d.ts → notification.d.mts} +0 -0
- /package/dist/lib/{runScript.d.ts → runScript.d.mts} +0 -0
- /package/dist/lib/{time.d.ts → time.d.mts} +0 -0
- /package/dist/lib/{wait.d.ts → wait.d.mts} +0 -0
- /package/dist/polyfill/{Console.d.ts → Console.d.mts} +0 -0
- /package/dist/polyfill/{Lodash.d.ts → Lodash.d.mts} +0 -0
- /package/dist/polyfill/{StatusTexts.d.ts → StatusTexts.d.mts} +0 -0
- /package/dist/polyfill/{fetch.d.ts → fetch.d.mts} +0 -0
package/dist/lib/wait.mjs
CHANGED
|
@@ -1,50 +1,151 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
17
|
-
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
18
|
-
return privateMap.get(receiver);
|
|
19
|
-
}
|
|
20
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
21
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
22
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
23
|
-
}
|
|
24
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
25
|
-
_check_private_redeclaration(obj, privateMap);
|
|
26
|
-
privateMap.set(obj, value);
|
|
27
|
-
}
|
|
28
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
29
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
30
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
function _define_property(obj, key, value) {
|
|
34
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
35
|
-
value: value,
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true
|
|
39
|
-
});
|
|
40
|
-
else obj[key] = value;
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
var _counts = /*#__PURE__*/ new WeakMap(), _groups = /*#__PURE__*/ new WeakMap(), _times = /*#__PURE__*/ new WeakMap(), _level = /*#__PURE__*/ new WeakMap();
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _ConsoleFactory_counts, _ConsoleFactory_groups, _ConsoleFactory_times, _ConsoleFactory_level;
|
|
13
|
+
import { $app } from '../lib/app.mjs';
|
|
44
14
|
class ConsoleFactory {
|
|
15
|
+
constructor() {
|
|
16
|
+
_ConsoleFactory_counts.set(this, new Map([]));
|
|
17
|
+
_ConsoleFactory_groups.set(this, []);
|
|
18
|
+
_ConsoleFactory_times.set(this, new Map([]));
|
|
19
|
+
Object.defineProperty(this, "clear", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: () => { }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "count", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: (label = 'default') => {
|
|
30
|
+
if (__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").has(label)) {
|
|
31
|
+
__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").set(label, __classPrivateFieldGet(this, _ConsoleFactory_counts, "f").get(label) ?? 0 + 1);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").set(label, 0);
|
|
35
|
+
}
|
|
36
|
+
this.log(`${label}: ${__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").get(label)}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "countReset", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: (label = 'default') => {
|
|
44
|
+
switch (__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").has(label)) {
|
|
45
|
+
case true:
|
|
46
|
+
__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").set(label, 0);
|
|
47
|
+
this.log(`${label}: ${__classPrivateFieldGet(this, _ConsoleFactory_counts, "f").get(label)}`);
|
|
48
|
+
break;
|
|
49
|
+
case false:
|
|
50
|
+
this.warn(`Counter "${label}" doesn’t exist`);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, "debug", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: (...args) => {
|
|
60
|
+
if (__classPrivateFieldGet(this, _ConsoleFactory_level, "f") < 4)
|
|
61
|
+
return;
|
|
62
|
+
this.log(...args.map((m) => `🅱️ ${m}`));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "exception", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: (...msg) => this.error(...msg)
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "group", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: (label) => __classPrivateFieldGet(this, _ConsoleFactory_groups, "f").unshift(label)
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "groupEnd", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: () => __classPrivateFieldGet(this, _ConsoleFactory_groups, "f").shift()
|
|
82
|
+
});
|
|
83
|
+
_ConsoleFactory_level.set(this, 3);
|
|
84
|
+
Object.defineProperty(this, "log", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: (...args) => {
|
|
89
|
+
if (__classPrivateFieldGet(this, _ConsoleFactory_level, "f") === 0)
|
|
90
|
+
return;
|
|
91
|
+
let msg = args;
|
|
92
|
+
msg = msg.map((item) => {
|
|
93
|
+
let log = item;
|
|
94
|
+
switch (typeof log) {
|
|
95
|
+
case 'object':
|
|
96
|
+
log = JSON.stringify(log);
|
|
97
|
+
break;
|
|
98
|
+
case 'bigint':
|
|
99
|
+
case 'number':
|
|
100
|
+
case 'boolean':
|
|
101
|
+
case 'string':
|
|
102
|
+
log = log.toString();
|
|
103
|
+
break;
|
|
104
|
+
case 'undefined':
|
|
105
|
+
default:
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return log;
|
|
109
|
+
});
|
|
110
|
+
__classPrivateFieldGet(this, _ConsoleFactory_groups, "f").forEach((group) => {
|
|
111
|
+
msg = msg.map((log) => ` ${log}`);
|
|
112
|
+
msg.unshift(`▼ ${group}:`);
|
|
113
|
+
});
|
|
114
|
+
msg = ['', ...msg];
|
|
115
|
+
console.log(msg.join('\n'));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(this, "time", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: (label = 'default') => __classPrivateFieldGet(this, _ConsoleFactory_times, "f").set(label, Date.now())
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(this, "timeEnd", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: (label = 'default') => __classPrivateFieldGet(this, _ConsoleFactory_times, "f").delete(label)
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(this, "timeLog", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
configurable: true,
|
|
133
|
+
writable: true,
|
|
134
|
+
value: (label = 'default') => {
|
|
135
|
+
const time = __classPrivateFieldGet(this, _ConsoleFactory_times, "f").get(label);
|
|
136
|
+
if (time) {
|
|
137
|
+
this.log(`${label}: ${Date.now() - time}ms`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.warn(`Timer "${label}" doesn’t exist`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
45
145
|
error(...msg) {
|
|
46
|
-
if (
|
|
47
|
-
|
|
146
|
+
if (__classPrivateFieldGet(this, _ConsoleFactory_level, "f") < 1)
|
|
147
|
+
return;
|
|
148
|
+
switch ($app) {
|
|
48
149
|
case 'Surge':
|
|
49
150
|
case 'Loon':
|
|
50
151
|
case 'Stash':
|
|
@@ -52,22 +153,25 @@ class ConsoleFactory {
|
|
|
52
153
|
case 'Shadowrocket':
|
|
53
154
|
case 'Quantumult X':
|
|
54
155
|
case 'Node.js':
|
|
55
|
-
this.log(...msg.map((m)=>{
|
|
56
|
-
if (m instanceof Error)
|
|
156
|
+
this.log(...msg.map((m) => {
|
|
157
|
+
if (m instanceof Error) {
|
|
158
|
+
return `❌ ${m.stack}`;
|
|
159
|
+
}
|
|
57
160
|
return `❌ ${m}`;
|
|
58
161
|
}));
|
|
59
162
|
break;
|
|
60
163
|
default:
|
|
61
|
-
this.log(...msg.map((m)
|
|
164
|
+
this.log(...msg.map((m) => `❌ ${m}`));
|
|
62
165
|
break;
|
|
63
166
|
}
|
|
64
167
|
}
|
|
65
168
|
info(...msg) {
|
|
66
|
-
if (
|
|
67
|
-
|
|
169
|
+
if (__classPrivateFieldGet(this, _ConsoleFactory_level, "f") < 3)
|
|
170
|
+
return;
|
|
171
|
+
this.log(...msg.map((m) => `ℹ️ ${m}`));
|
|
68
172
|
}
|
|
69
173
|
get logLevel() {
|
|
70
|
-
switch(
|
|
174
|
+
switch (__classPrivateFieldGet(this, _ConsoleFactory_level, "f")) {
|
|
71
175
|
case 0:
|
|
72
176
|
return 'OFF';
|
|
73
177
|
case 1:
|
|
@@ -83,9 +187,9 @@ class ConsoleFactory {
|
|
|
83
187
|
return 'INFO';
|
|
84
188
|
}
|
|
85
189
|
}
|
|
86
|
-
set logLevel(
|
|
87
|
-
let level =
|
|
88
|
-
switch(typeof level){
|
|
190
|
+
set logLevel(_level) {
|
|
191
|
+
let level = _level;
|
|
192
|
+
switch (typeof level) {
|
|
89
193
|
case 'string':
|
|
90
194
|
level = level.toLowerCase();
|
|
91
195
|
break;
|
|
@@ -96,121 +200,43 @@ class ConsoleFactory {
|
|
|
96
200
|
level = 'warn';
|
|
97
201
|
break;
|
|
98
202
|
}
|
|
99
|
-
switch(level){
|
|
203
|
+
switch (level) {
|
|
100
204
|
case 0:
|
|
101
205
|
case 'off':
|
|
102
|
-
|
|
206
|
+
__classPrivateFieldSet(this, _ConsoleFactory_level, 0, "f");
|
|
103
207
|
break;
|
|
104
208
|
case 1:
|
|
105
209
|
case 'error':
|
|
106
|
-
|
|
210
|
+
__classPrivateFieldSet(this, _ConsoleFactory_level, 1, "f");
|
|
107
211
|
break;
|
|
108
212
|
case 3:
|
|
109
213
|
case 'info':
|
|
110
|
-
|
|
214
|
+
__classPrivateFieldSet(this, _ConsoleFactory_level, 3, "f");
|
|
111
215
|
break;
|
|
112
216
|
case 4:
|
|
113
217
|
case 'debug':
|
|
114
|
-
|
|
218
|
+
__classPrivateFieldSet(this, _ConsoleFactory_level, 4, "f");
|
|
115
219
|
break;
|
|
116
220
|
case 5:
|
|
117
221
|
case 'all':
|
|
118
|
-
|
|
222
|
+
__classPrivateFieldSet(this, _ConsoleFactory_level, 5, "f");
|
|
119
223
|
break;
|
|
120
224
|
case 2:
|
|
121
225
|
case 'warn':
|
|
122
226
|
case 'warning':
|
|
123
227
|
default:
|
|
124
|
-
|
|
228
|
+
__classPrivateFieldSet(this, _ConsoleFactory_level, 2, "f");
|
|
125
229
|
break;
|
|
126
230
|
}
|
|
127
231
|
}
|
|
128
232
|
warn(...args) {
|
|
129
|
-
if (
|
|
233
|
+
if (__classPrivateFieldGet(this, _ConsoleFactory_level, "f") < 2) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
130
236
|
let msg = args;
|
|
131
|
-
msg = msg.map((m)
|
|
237
|
+
msg = msg.map((m) => `⚠️ ${m}`);
|
|
132
238
|
this.log(...msg);
|
|
133
239
|
}
|
|
134
|
-
constructor(){
|
|
135
|
-
_class_private_field_init(this, _counts, {
|
|
136
|
-
writable: true,
|
|
137
|
-
value: new Map([])
|
|
138
|
-
});
|
|
139
|
-
_class_private_field_init(this, _groups, {
|
|
140
|
-
writable: true,
|
|
141
|
-
value: []
|
|
142
|
-
});
|
|
143
|
-
_class_private_field_init(this, _times, {
|
|
144
|
-
writable: true,
|
|
145
|
-
value: new Map([])
|
|
146
|
-
});
|
|
147
|
-
_define_property(this, "clear", ()=>{});
|
|
148
|
-
_define_property(this, "count", (label = 'default')=>{
|
|
149
|
-
if (_class_private_field_get(this, _counts).has(label)) _class_private_field_get(this, _counts).set(label, _class_private_field_get(this, _counts).get(label) ?? 1);
|
|
150
|
-
else _class_private_field_get(this, _counts).set(label, 0);
|
|
151
|
-
this.log(`${label}: ${_class_private_field_get(this, _counts).get(label)}`);
|
|
152
|
-
});
|
|
153
|
-
_define_property(this, "countReset", (label = 'default')=>{
|
|
154
|
-
switch(_class_private_field_get(this, _counts).has(label)){
|
|
155
|
-
case true:
|
|
156
|
-
_class_private_field_get(this, _counts).set(label, 0);
|
|
157
|
-
this.log(`${label}: ${_class_private_field_get(this, _counts).get(label)}`);
|
|
158
|
-
break;
|
|
159
|
-
case false:
|
|
160
|
-
this.warn(`Counter "${label}" doesn’t exist`);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
_define_property(this, "debug", (...args)=>{
|
|
165
|
-
if (_class_private_field_get(this, _level) < 4) return;
|
|
166
|
-
this.log(...args.map((m)=>`🅱️ ${m}`));
|
|
167
|
-
});
|
|
168
|
-
_define_property(this, "exception", (...msg)=>this.error(...msg));
|
|
169
|
-
_define_property(this, "group", (label)=>_class_private_field_get(this, _groups).unshift(label));
|
|
170
|
-
_define_property(this, "groupEnd", ()=>_class_private_field_get(this, _groups).shift());
|
|
171
|
-
_class_private_field_init(this, _level, {
|
|
172
|
-
writable: true,
|
|
173
|
-
value: 3
|
|
174
|
-
});
|
|
175
|
-
_define_property(this, "log", (...args)=>{
|
|
176
|
-
if (0 === _class_private_field_get(this, _level)) return;
|
|
177
|
-
let msg = args;
|
|
178
|
-
msg = msg.map((item)=>{
|
|
179
|
-
let log = item;
|
|
180
|
-
switch(typeof log){
|
|
181
|
-
case 'object':
|
|
182
|
-
log = JSON.stringify(log);
|
|
183
|
-
break;
|
|
184
|
-
case 'bigint':
|
|
185
|
-
case 'number':
|
|
186
|
-
case 'boolean':
|
|
187
|
-
case 'string':
|
|
188
|
-
log = log.toString();
|
|
189
|
-
break;
|
|
190
|
-
case 'undefined':
|
|
191
|
-
default:
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
return log;
|
|
195
|
-
});
|
|
196
|
-
_class_private_field_get(this, _groups).forEach((group)=>{
|
|
197
|
-
msg = msg.map((log)=>` ${log}`);
|
|
198
|
-
msg.unshift(`▼ ${group}:`);
|
|
199
|
-
});
|
|
200
|
-
msg = [
|
|
201
|
-
'',
|
|
202
|
-
...msg
|
|
203
|
-
];
|
|
204
|
-
console.log(msg.join('\n'));
|
|
205
|
-
});
|
|
206
|
-
_define_property(this, "time", (label = 'default')=>_class_private_field_get(this, _times).set(label, Date.now()));
|
|
207
|
-
_define_property(this, "timeEnd", (label = 'default')=>_class_private_field_get(this, _times).delete(label));
|
|
208
|
-
_define_property(this, "timeLog", (label = 'default')=>{
|
|
209
|
-
const time = _class_private_field_get(this, _times).get(label);
|
|
210
|
-
if (time) this.log(`${label}: ${Date.now() - time}ms`);
|
|
211
|
-
else this.warn(`Timer "${label}" doesn’t exist`);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
240
|
}
|
|
215
|
-
|
|
216
|
-
export
|
|
241
|
+
_ConsoleFactory_counts = new WeakMap(), _ConsoleFactory_groups = new WeakMap(), _ConsoleFactory_times = new WeakMap(), _ConsoleFactory_level = new WeakMap();
|
|
242
|
+
export const Console = new ConsoleFactory();
|
package/dist/polyfill/Lodash.mjs
CHANGED
|
@@ -3,44 +3,53 @@ const ESCAPE_MAP = {
|
|
|
3
3
|
'<': '<',
|
|
4
4
|
'>': '>',
|
|
5
5
|
'"': '"',
|
|
6
|
-
"'": '''
|
|
6
|
+
"'": ''',
|
|
7
7
|
};
|
|
8
8
|
const UNESCAPE_MAP = {
|
|
9
9
|
'&': '&',
|
|
10
10
|
'<': '<',
|
|
11
11
|
'>': '>',
|
|
12
12
|
'"': '"',
|
|
13
|
-
''': "'"
|
|
13
|
+
''': "'",
|
|
14
14
|
};
|
|
15
15
|
const ESCAPE_REGEX = /[&<>"']/g;
|
|
16
16
|
const UNESCAPE_REGEX = /&(amp|lt|gt|quot|#39);/g;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
|
|
18
|
+
export const escape = (str) => {
|
|
19
|
+
if (!ESCAPE_REGEX.test(str))
|
|
20
|
+
return str;
|
|
19
21
|
ESCAPE_REGEX.lastIndex = 0;
|
|
20
|
-
return str.replace(ESCAPE_REGEX, (match)=>ESCAPE_MAP[match]);
|
|
22
|
+
return str.replace(ESCAPE_REGEX, (match) => ESCAPE_MAP[match]);
|
|
21
23
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
|
|
25
|
+
export const unescape = (str) => {
|
|
26
|
+
if (!UNESCAPE_REGEX.test(str))
|
|
27
|
+
return str;
|
|
24
28
|
UNESCAPE_REGEX.lastIndex = 0;
|
|
25
|
-
return str.replace(UNESCAPE_REGEX, (match)=>UNESCAPE_MAP[match]);
|
|
29
|
+
return str.replace(UNESCAPE_REGEX, (match) => UNESCAPE_MAP[match]);
|
|
26
30
|
};
|
|
27
|
-
const toPath = (value)=>value
|
|
28
|
-
|
|
31
|
+
export const toPath = (value) => value
|
|
32
|
+
.replace(/\[(\d+)\]/g, '.$1')
|
|
33
|
+
.split('.')
|
|
34
|
+
.filter(Boolean);
|
|
35
|
+
export const get = (obj, path, defaultValue) => {
|
|
29
36
|
const getPath = Array.isArray(path) ? path : toPath(path);
|
|
30
|
-
const result = getPath.reduce((previousValue, currentValue)=>Object(previousValue)[currentValue], obj);
|
|
31
|
-
return
|
|
37
|
+
const result = getPath.reduce((previousValue, currentValue) => Object(previousValue)[currentValue], obj);
|
|
38
|
+
return result === undefined ? defaultValue : result;
|
|
32
39
|
};
|
|
33
|
-
const set = (obj, path, value)=>{
|
|
34
|
-
const setPath = Array.isArray(path) ? path : toPath(path);
|
|
35
|
-
setPath.slice(0, -1).reduce((prev, key, index)=>{
|
|
36
|
-
if (
|
|
40
|
+
export const set = (obj, path, value) => {
|
|
41
|
+
const setPath = (Array.isArray(path) ? path : toPath(path));
|
|
42
|
+
setPath.slice(0, -1).reduce((prev, key, index) => {
|
|
43
|
+
if (typeof prev[key] !== 'object' || prev[key] === null) {
|
|
44
|
+
prev[key] = /^\d+$/.test(setPath[index + 1]) ? [] : {};
|
|
45
|
+
}
|
|
37
46
|
return prev[key];
|
|
38
47
|
}, obj)[setPath[setPath.length - 1]] = value;
|
|
39
48
|
return obj;
|
|
40
49
|
};
|
|
41
|
-
const unset = (obj, path)=>{
|
|
50
|
+
export const unset = (obj, path) => {
|
|
42
51
|
const unsetPath = Array.isArray(path) ? path : toPath(path);
|
|
43
|
-
return unsetPath.reduce((previousValue, currentValue, currentIndex)=>{
|
|
52
|
+
return unsetPath.reduce((previousValue, currentValue, currentIndex) => {
|
|
44
53
|
if (currentIndex === path.length - 1) {
|
|
45
54
|
delete previousValue[currentValue];
|
|
46
55
|
return true;
|
|
@@ -48,25 +57,26 @@ const unset = (obj, path)=>{
|
|
|
48
57
|
return Object(previousValue)[currentValue];
|
|
49
58
|
}, obj);
|
|
50
59
|
};
|
|
51
|
-
const omit = (obj, paths)=>{
|
|
52
|
-
const result = {
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
paths.forEach((path)=>unset(result, path));
|
|
60
|
+
export const omit = (obj, paths) => {
|
|
61
|
+
const result = { ...obj };
|
|
62
|
+
paths.forEach((path) => unset(result, path));
|
|
56
63
|
return result;
|
|
57
64
|
};
|
|
58
|
-
const pick = (obj, paths)=>
|
|
65
|
+
export const pick = (obj, paths) => {
|
|
66
|
+
return Object.entries(obj)
|
|
67
|
+
.filter(([key]) => paths.includes(key))
|
|
68
|
+
.reduce((result, [key, value]) => {
|
|
59
69
|
result[key] = value;
|
|
60
70
|
return result;
|
|
61
71
|
}, {});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
};
|
|
73
|
+
export const Lodash = {
|
|
74
|
+
escape,
|
|
75
|
+
unescape,
|
|
65
76
|
toPath,
|
|
66
77
|
get,
|
|
67
78
|
set,
|
|
68
79
|
unset,
|
|
69
80
|
omit,
|
|
70
|
-
pick
|
|
81
|
+
pick,
|
|
71
82
|
};
|
|
72
|
-
export { Lodash, Lodash_rslib_entry_escape as escape, get, omit, pick, set, toPath, Lodash_rslib_entry_unescape as unescape, unset };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const StatusTexts = {
|
|
1
|
+
export const StatusTexts = {
|
|
2
2
|
100: 'Continue',
|
|
3
3
|
101: 'Switching Protocols',
|
|
4
4
|
102: 'Processing',
|
|
@@ -58,6 +58,5 @@ const StatusTexts = {
|
|
|
58
58
|
507: 'Insufficient Storage',
|
|
59
59
|
508: 'Loop Detected',
|
|
60
60
|
510: 'Not Extended',
|
|
61
|
-
511: 'Network Authentication Required'
|
|
61
|
+
511: 'Network Authentication Required',
|
|
62
62
|
};
|
|
63
|
-
export { StatusTexts };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class StorageClass {
|
|
2
|
+
#private;
|
|
3
|
+
private data;
|
|
4
|
+
private readonly dataFile;
|
|
5
|
+
private readonly nameRegex;
|
|
6
|
+
constructor();
|
|
7
|
+
getItem<T = any>(keyName: string, defaultValue?: T): T;
|
|
8
|
+
setItem(keyName: string, value: any): boolean;
|
|
9
|
+
removeItem(keyName: string): boolean;
|
|
10
|
+
clear(): boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const Storage: StorageClass;
|