@wener/utils 1.1.5 → 1.1.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/README.md +5 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/system/index.js +1 -1
- package/dist/system/index.js.map +1 -1
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/lib/arrays/MaybeArray.js.map +1 -1
- package/lib/asyncs/createLazyPromise.js +55 -0
- package/lib/asyncs/createLazyPromise.js.map +1 -0
- package/lib/asyncs/timeout.js +1 -1
- package/lib/asyncs/timeout.js.map +1 -1
- package/lib/browsers/copy.js +2 -3
- package/lib/browsers/copy.js.map +1 -1
- package/lib/browsers/loaders.js +6 -11
- package/lib/browsers/loaders.js.map +1 -1
- package/lib/crypto/{hex.js → base.js} +1 -1
- package/lib/crypto/base.js.map +1 -0
- package/lib/crypto/hashing.js +4 -4
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/crypto/randomUUID.js +3 -5
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/i18n/createTranslate.js +37 -0
- package/lib/i18n/createTranslate.js.map +1 -0
- package/lib/index.js +12 -7
- package/lib/index.js.map +1 -1
- package/lib/io/ArrayBuffers.js +164 -0
- package/lib/io/ArrayBuffers.js.map +1 -0
- package/lib/io/isBuffer.js +1 -1
- package/lib/io/isBuffer.js.map +1 -1
- package/lib/io/isTransferable.js +23 -0
- package/lib/io/isTransferable.js.map +1 -0
- package/lib/isomorphics/structuredClone.js +70 -0
- package/lib/isomorphics/structuredClone.js.map +1 -0
- package/lib/langs/classOf.js +6 -0
- package/lib/langs/classOf.js.map +1 -0
- package/lib/{validations/dequal.js → langs/deepEqual.js} +7 -7
- package/lib/langs/deepEqual.js.map +1 -0
- package/lib/{validations/shallow.js → langs/shallowEqual.js} +3 -3
- package/lib/langs/shallowEqual.js.map +1 -0
- package/lib/logging/createNoopLogger.js.map +1 -1
- package/lib/modules/isModule.js.map +1 -1
- package/lib/modules/parseModuleId.js +7 -5
- package/lib/modules/parseModuleId.js.map +1 -1
- package/lib/objects/parseObjectPath.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/server/polyfillBrowser.js +12 -0
- package/lib/server/polyfillBrowser.js.map +1 -0
- package/lib/server/polyfillCrypto.js +10 -0
- package/lib/server/polyfillCrypto.js.map +1 -0
- package/lib/server/polyfillFetch.js +31 -0
- package/lib/server/polyfillFetch.js.map +1 -0
- package/lib/server/polyfillJsDom.js +49 -0
- package/lib/server/polyfillJsDom.js.map +1 -0
- package/lib/server.js +4 -1
- package/lib/server.js.map +1 -1
- package/lib/{formats → strings}/formatBytes.js +1 -1
- package/lib/{formats → strings}/formatBytes.js.map +1 -1
- package/lib/strings/renderTemplate.js +4 -2
- package/lib/strings/renderTemplate.js.map +1 -1
- package/lib/validations/isUUID.js +6 -0
- package/lib/validations/isUUID.js.map +1 -0
- package/package.json +14 -2
- package/src/arrays/MaybeArray.ts +1 -1
- package/src/asyncs/createLazyPromise.test.ts +39 -0
- package/src/asyncs/createLazyPromise.ts +63 -0
- package/src/asyncs/generatorOfStream.ts +1 -0
- package/src/asyncs/timeout.ts +1 -1
- package/src/browsers/copy.ts +6 -5
- package/src/browsers/loaders.ts +6 -11
- package/src/crypto/{hex.ts → base.ts} +3 -0
- package/src/crypto/hashing.test.ts +12 -8
- package/src/crypto/hashing.ts +4 -4
- package/src/crypto/randomUUID.ts +6 -4
- package/src/i18n/createTranslate.test.ts +155 -0
- package/src/i18n/createTranslate.ts +52 -0
- package/src/index.ts +22 -9
- package/src/io/AbstractEncoding.ts +21 -0
- package/src/io/ArrayBuffer.test-d.ts +4 -0
- package/src/io/ArrayBuffers.base64.test.ts +61 -0
- package/src/io/ArrayBuffers.test.ts +23 -0
- package/src/io/ArrayBuffers.ts +272 -0
- package/src/io/Buffer.ts +16 -0
- package/src/io/isBuffer.test.ts +9 -0
- package/src/io/isBuffer.ts +3 -8
- package/src/io/isTransferable.test.ts +10 -0
- package/src/io/isTransferable.ts +50 -0
- package/src/isomorphics/structuredClone.test.ts +14 -0
- package/src/isomorphics/structuredClone.ts +88 -0
- package/src/langs/classOf.ts +3 -0
- package/src/{validations/dequal.test.ts → langs/deepEqual.test.ts} +2 -2
- package/src/{validations/dequal.ts → langs/deepEqual.ts} +6 -5
- package/src/langs/langs.test.ts +23 -0
- package/src/{validations/shallow.ts → langs/shallowEqual.ts} +2 -2
- package/src/logging/Logger.ts +6 -0
- package/src/logging/createNoopLogger.ts +1 -1
- package/src/logging/logger.test.ts +3 -3
- package/src/modules/isModule.ts +3 -0
- package/src/modules/parseModuleId.test.ts +7 -2
- package/src/modules/parseModuleId.ts +15 -9
- package/src/objects/get.test-d.ts +51 -0
- package/src/objects/get.test.ts +2 -55
- package/src/objects/parseObjectPath.ts +4 -3
- package/src/objects/set.test.ts +32 -31
- package/src/objects/set.ts +2 -2
- package/src/server/polyfillBrowser.test.ts +15 -0
- package/src/server/polyfillBrowser.ts +17 -0
- package/src/server/polyfillCrypto.ts +7 -0
- package/src/server/polyfillFetch.ts +28 -0
- package/src/server/polyfillJsDom.ts +85 -0
- package/src/server.ts +4 -1
- package/src/{formats → strings}/formatBytes.ts +1 -1
- package/src/strings/renderTemplate.test.ts +1 -0
- package/src/strings/renderTemplate.ts +12 -6
- package/src/typedoc.ts +2 -0
- package/src/validations/isUUID.ts +3 -0
- package/tsconfig.json +2 -1
- package/lib/asyncs/LazyPromise.js +0 -27
- package/lib/asyncs/LazyPromise.js.map +0 -1
- package/lib/crypto/hex.js.map +0 -1
- package/lib/server/polyfill.js +0 -8
- package/lib/server/polyfill.js.map +0 -1
- package/lib/shim/urljoin.js +0 -51
- package/lib/shim/urljoin.js.map +0 -1
- package/lib/validations/dequal.js.map +0 -1
- package/lib/validations/shallow.js.map +0 -1
- package/src/asyncs/LazyPromise.ts +0 -29
- package/src/server/polyfill.ts +0 -5
- package/src/shim/urljoin.test.ts +0 -6
- package/src/shim/urljoin.ts +0 -75
- package/src/types.d.ts +0 -7
package/src/objects/set.test.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/* eslint no-proto:0 no-prototype-builtins:0 */
|
|
1
2
|
import test from 'ava';
|
|
2
3
|
import { set } from './set';
|
|
3
4
|
|
|
4
5
|
test('set basics', (t) => {
|
|
5
6
|
t.is(set({}, 'c', 3), undefined, 'should not give return value');
|
|
6
7
|
{
|
|
7
|
-
|
|
8
|
+
const item = { foo: 1 };
|
|
8
9
|
set(item, 'bar', 123);
|
|
9
10
|
t.is(item, item);
|
|
10
11
|
t.deepEqual(
|
|
@@ -30,7 +31,7 @@ test('set objects', (t) => {
|
|
|
30
31
|
const set = (a: any, b: any, c: any) => orig(a, b, c, isMerge);
|
|
31
32
|
const verb = isMerge ? 'merge' : 'overwrite';
|
|
32
33
|
objects(`should ${verb} existing object value :: simple`, () => {
|
|
33
|
-
|
|
34
|
+
const { input } = prepare({
|
|
34
35
|
hello: { a: 1 },
|
|
35
36
|
});
|
|
36
37
|
|
|
@@ -51,7 +52,7 @@ test('set objects', (t) => {
|
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
objects(`should ${verb} existing object value :: nested`, () => {
|
|
54
|
-
|
|
55
|
+
const { input, copy } = prepare({
|
|
55
56
|
a: {
|
|
56
57
|
b: {
|
|
57
58
|
c: 123,
|
|
@@ -71,7 +72,7 @@ test('set objects', (t) => {
|
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
objects(`should ${verb} existing array value :: simple`, () => {
|
|
74
|
-
|
|
75
|
+
const { input } = prepare([{ foo: 1 }]);
|
|
75
76
|
|
|
76
77
|
set(input, '0', { bar: 2 });
|
|
77
78
|
|
|
@@ -83,7 +84,7 @@ test('set objects', (t) => {
|
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
objects(`should ${verb} existing array value :: nested`, () => {
|
|
86
|
-
|
|
87
|
+
const { input } = prepare([
|
|
87
88
|
{ name: 'bob', age: 56, friends: ['foobar'] },
|
|
88
89
|
{ name: 'alice', age: 47, friends: ['mary'] },
|
|
89
90
|
]);
|
|
@@ -118,7 +119,7 @@ test('set arrays', (t) => {
|
|
|
118
119
|
f();
|
|
119
120
|
};
|
|
120
121
|
arrays('should create array instead of object via numeric key :: simple', () => {
|
|
121
|
-
|
|
122
|
+
const input: any = { a: 1 };
|
|
122
123
|
set(input, 'e.0', 2);
|
|
123
124
|
t.true(Array.isArray(input.e));
|
|
124
125
|
t.is(input.e[0], 2);
|
|
@@ -129,7 +130,7 @@ test('set arrays', (t) => {
|
|
|
129
130
|
});
|
|
130
131
|
|
|
131
132
|
arrays('should create array instead of object via numeric key :: nested', () => {
|
|
132
|
-
|
|
133
|
+
const input: any = { a: 1 };
|
|
133
134
|
set(input, 'e.0.0', 123);
|
|
134
135
|
t.true(input.e instanceof Array);
|
|
135
136
|
t.is(input.e[0][0], 123);
|
|
@@ -140,7 +141,7 @@ test('set arrays', (t) => {
|
|
|
140
141
|
});
|
|
141
142
|
|
|
142
143
|
arrays('should be able to create object inside of array', () => {
|
|
143
|
-
|
|
144
|
+
const input: any = {};
|
|
144
145
|
set(input, ['x', '0', 'z'], 123);
|
|
145
146
|
t.true(input.x instanceof Array);
|
|
146
147
|
t.deepEqual(input, {
|
|
@@ -149,16 +150,16 @@ test('set arrays', (t) => {
|
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
arrays('should create arrays with hole(s) if needed', () => {
|
|
152
|
-
|
|
153
|
+
const input: any = {};
|
|
153
154
|
set(input, ['x', '1', 'z'], 123);
|
|
154
155
|
t.true(input.x instanceof Array);
|
|
155
156
|
t.deepEqual(input, {
|
|
156
|
-
x: [, { z: 123 }],
|
|
157
|
+
x: [undefined, { z: 123 }],
|
|
157
158
|
});
|
|
158
159
|
});
|
|
159
160
|
|
|
160
161
|
arrays('should create object from decimal-like key :: array :: zero :: string', () => {
|
|
161
|
-
|
|
162
|
+
const input: any = {};
|
|
162
163
|
set(input, ['x', '10.0', 'z'], 123);
|
|
163
164
|
t.false(input.x instanceof Array);
|
|
164
165
|
t.deepEqual(input, {
|
|
@@ -171,17 +172,17 @@ test('set arrays', (t) => {
|
|
|
171
172
|
});
|
|
172
173
|
|
|
173
174
|
arrays('should create array from decimal-like key :: array :: zero :: number', () => {
|
|
174
|
-
|
|
175
|
+
const input: any = {};
|
|
175
176
|
set(input, ['x', 10.0, 'z'], 123);
|
|
176
177
|
t.true(input.x instanceof Array);
|
|
177
178
|
|
|
178
|
-
|
|
179
|
+
const x = Array(10);
|
|
179
180
|
x.push({ z: 123 });
|
|
180
181
|
t.deepEqual(input, { x });
|
|
181
182
|
});
|
|
182
183
|
|
|
183
184
|
arrays('should create object from decimal-like key :: array :: nonzero', () => {
|
|
184
|
-
|
|
185
|
+
const input: any = {};
|
|
185
186
|
set(input, ['x', '10.2', 'z'], 123);
|
|
186
187
|
t.false(input.x instanceof Array);
|
|
187
188
|
t.deepEqual(input, {
|
|
@@ -200,8 +201,8 @@ test('set pollution', (t) => {
|
|
|
200
201
|
f();
|
|
201
202
|
};
|
|
202
203
|
pollution('should protect against "__proto__" assignment', () => {
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
const input: any = { abc: 123 };
|
|
205
|
+
const before = input.__proto__;
|
|
205
206
|
set(input, '__proto__.hello', 123);
|
|
206
207
|
|
|
207
208
|
t.deepEqual(input.__proto__, before);
|
|
@@ -211,8 +212,8 @@ test('set pollution', (t) => {
|
|
|
211
212
|
});
|
|
212
213
|
|
|
213
214
|
pollution('should protect against "__proto__" assignment :: nested', () => {
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
const input: any = { abc: 123 };
|
|
216
|
+
const before = input.__proto__;
|
|
216
217
|
set(input, ['xyz', '__proto__', 'hello'], 123);
|
|
217
218
|
|
|
218
219
|
t.deepEqual(input.__proto__, before);
|
|
@@ -227,7 +228,7 @@ test('set pollution', (t) => {
|
|
|
227
228
|
});
|
|
228
229
|
|
|
229
230
|
pollution('should ignore "prototype" assignment', () => {
|
|
230
|
-
|
|
231
|
+
const input: any = { a: 123 };
|
|
231
232
|
set(input, 'a.prototype.hello', 'world');
|
|
232
233
|
|
|
233
234
|
t.is(input.a.prototype, undefined);
|
|
@@ -243,7 +244,7 @@ test('set pollution', (t) => {
|
|
|
243
244
|
});
|
|
244
245
|
|
|
245
246
|
pollution('should ignore "constructor" assignment :: direct', () => {
|
|
246
|
-
|
|
247
|
+
const input: any = { a: 123 };
|
|
247
248
|
|
|
248
249
|
function Custom() {
|
|
249
250
|
//
|
|
@@ -259,7 +260,7 @@ test('set pollution', (t) => {
|
|
|
259
260
|
});
|
|
260
261
|
|
|
261
262
|
pollution('should ignore "constructor" assignment :: nested', () => {
|
|
262
|
-
|
|
263
|
+
const input: any = {};
|
|
263
264
|
|
|
264
265
|
set(input, 'constructor.prototype.hello', 'world');
|
|
265
266
|
t.is(input.hasOwnProperty('constructor'), false);
|
|
@@ -272,7 +273,7 @@ test('set pollution', (t) => {
|
|
|
272
273
|
|
|
273
274
|
// Test for CVE-2022-25645 - CWE-1321
|
|
274
275
|
pollution('should ignore JSON.parse crafted object with "__proto__" key', () => {
|
|
275
|
-
|
|
276
|
+
const a: any = { b: { c: 1 } };
|
|
276
277
|
t.is(a.polluted, undefined);
|
|
277
278
|
set(a, 'b', JSON.parse('{"__proto__":{"polluted":"Yes!"}}'));
|
|
278
279
|
t.is(a.polluted, undefined);
|
|
@@ -284,19 +285,19 @@ test('set assigns', (t) => {
|
|
|
284
285
|
f();
|
|
285
286
|
};
|
|
286
287
|
assigns('should add value to key path :: shallow :: string', () => {
|
|
287
|
-
|
|
288
|
+
const input: any = {};
|
|
288
289
|
set(input, 'abc', 123);
|
|
289
290
|
t.deepEqual(input, { abc: 123 });
|
|
290
291
|
});
|
|
291
292
|
|
|
292
293
|
assigns('should add value to key path :: shallow :: array', () => {
|
|
293
|
-
|
|
294
|
+
const input: any = {};
|
|
294
295
|
set(input, ['abc'], 123);
|
|
295
296
|
t.deepEqual(input, { abc: 123 });
|
|
296
297
|
});
|
|
297
298
|
|
|
298
299
|
assigns('should add value to key path :: nested :: string', () => {
|
|
299
|
-
|
|
300
|
+
const input: any = {};
|
|
300
301
|
set(input, 'a.b.c', 123);
|
|
301
302
|
t.deepEqual(input, {
|
|
302
303
|
a: {
|
|
@@ -308,7 +309,7 @@ test('set assigns', (t) => {
|
|
|
308
309
|
});
|
|
309
310
|
|
|
310
311
|
assigns('should add value to key path :: nested :: array', () => {
|
|
311
|
-
|
|
312
|
+
const input: any = {};
|
|
312
313
|
set(input, ['a', 'b', 'c'], 123);
|
|
313
314
|
t.deepEqual(input, {
|
|
314
315
|
a: {
|
|
@@ -320,7 +321,7 @@ test('set assigns', (t) => {
|
|
|
320
321
|
});
|
|
321
322
|
|
|
322
323
|
assigns('should create Array via integer key :: string', () => {
|
|
323
|
-
|
|
324
|
+
const input: any = {};
|
|
324
325
|
set(input, ['foo', '0'], 123);
|
|
325
326
|
t.true(input.foo instanceof Array);
|
|
326
327
|
t.deepEqual(input, {
|
|
@@ -329,7 +330,7 @@ test('set assigns', (t) => {
|
|
|
329
330
|
});
|
|
330
331
|
|
|
331
332
|
assigns('should create Array via integer key :: number', () => {
|
|
332
|
-
|
|
333
|
+
const input: any = {};
|
|
333
334
|
set(input, ['foo', 0], 123);
|
|
334
335
|
t.true(input.foo instanceof Array);
|
|
335
336
|
t.deepEqual(input, {
|
|
@@ -343,7 +344,7 @@ test('set preserves', (t) => {
|
|
|
343
344
|
f();
|
|
344
345
|
};
|
|
345
346
|
preserves('should preserve existing object structure', () => {
|
|
346
|
-
|
|
347
|
+
const input = {
|
|
347
348
|
a: {
|
|
348
349
|
b: {
|
|
349
350
|
c: 123,
|
|
@@ -366,7 +367,7 @@ test('set preserves', (t) => {
|
|
|
366
367
|
});
|
|
367
368
|
|
|
368
369
|
preserves('should overwrite existing non-object values as object', () => {
|
|
369
|
-
|
|
370
|
+
const input = {
|
|
370
371
|
a: {
|
|
371
372
|
b: 123,
|
|
372
373
|
},
|
|
@@ -384,7 +385,7 @@ test('set preserves', (t) => {
|
|
|
384
385
|
});
|
|
385
386
|
|
|
386
387
|
preserves('should preserve existing object tree w/ array value', () => {
|
|
387
|
-
|
|
388
|
+
const input = {
|
|
388
389
|
a: {
|
|
389
390
|
b: {
|
|
390
391
|
c: 123,
|
package/src/objects/set.ts
CHANGED
|
@@ -22,8 +22,8 @@ export function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, va
|
|
|
22
22
|
: val
|
|
23
23
|
: typeof (x = current[k]) === typeof path
|
|
24
24
|
? x
|
|
25
|
-
: // @ts-
|
|
26
|
-
path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.')
|
|
25
|
+
: // @ts-expect-error hacky type check
|
|
26
|
+
path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line
|
|
27
27
|
? {}
|
|
28
28
|
: [];
|
|
29
29
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { polyfillBrowser } from './polyfillBrowser';
|
|
3
|
+
|
|
4
|
+
test.before(async () => {
|
|
5
|
+
await polyfillBrowser();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('polyfillBrowser', (t) => {
|
|
9
|
+
t.truthy(fetch);
|
|
10
|
+
t.truthy(window);
|
|
11
|
+
t.truthy(document);
|
|
12
|
+
t.truthy(crypto);
|
|
13
|
+
// not the same
|
|
14
|
+
t.not(window, globalThis);
|
|
15
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { polyfillCrypto } from './polyfillCrypto';
|
|
2
|
+
import { polyfillFetch } from './polyfillFetch';
|
|
3
|
+
import { polyfillJsDom } from './polyfillJsDom';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Polyfills the browser environment with the necessary APIs for the server.
|
|
7
|
+
* Currently, this includes:
|
|
8
|
+
* - `window`
|
|
9
|
+
* - `document`
|
|
10
|
+
* - `fetch`
|
|
11
|
+
* - `crypto`
|
|
12
|
+
*/
|
|
13
|
+
export async function polyfillBrowser() {
|
|
14
|
+
await polyfillCrypto();
|
|
15
|
+
await polyfillFetch();
|
|
16
|
+
await polyfillJsDom();
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export async function polyfillFetch() {
|
|
2
|
+
if ('fetch' in globalThis) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const {
|
|
6
|
+
default: fetch,
|
|
7
|
+
Response,
|
|
8
|
+
Headers,
|
|
9
|
+
Request,
|
|
10
|
+
AbortError,
|
|
11
|
+
FetchError,
|
|
12
|
+
FormData,
|
|
13
|
+
Blob,
|
|
14
|
+
File,
|
|
15
|
+
} = await import('node-fetch');
|
|
16
|
+
Object.assign(globalThis, {
|
|
17
|
+
fetch,
|
|
18
|
+
Response,
|
|
19
|
+
Headers,
|
|
20
|
+
Request,
|
|
21
|
+
AbortError,
|
|
22
|
+
FetchError,
|
|
23
|
+
FormData,
|
|
24
|
+
Blob,
|
|
25
|
+
File,
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
|
|
2
|
+
|
|
3
|
+
export async function polyfillJsDom() {
|
|
4
|
+
if (typeof window !== 'undefined') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { ResourceLoader, JSDOM } = await import('jsdom');
|
|
9
|
+
|
|
10
|
+
// https://github.com/lukechilds/window/blob/master/src/index.js
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
12
|
+
class Window {
|
|
13
|
+
constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {
|
|
14
|
+
const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;
|
|
15
|
+
const resources = new ResourceLoader({
|
|
16
|
+
proxy,
|
|
17
|
+
strictSSL,
|
|
18
|
+
userAgent,
|
|
19
|
+
});
|
|
20
|
+
return new JSDOM(
|
|
21
|
+
'',
|
|
22
|
+
Object.assign(jsdomOpts, {
|
|
23
|
+
resources,
|
|
24
|
+
}),
|
|
25
|
+
).window;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// https://github.com/lukechilds/browser-env/blob/master/src/index.js
|
|
30
|
+
// Default jsdom config.
|
|
31
|
+
// These settings must override any custom settings to make sure we can iterate
|
|
32
|
+
// over the window object.
|
|
33
|
+
const defaultJsdomConfig = {
|
|
34
|
+
// features: {
|
|
35
|
+
// FetchExternalResources: false,
|
|
36
|
+
// ProcessExternalResources: false,
|
|
37
|
+
// },
|
|
38
|
+
};
|
|
39
|
+
// IIFE executed on import to return an array of global Node.js properties that
|
|
40
|
+
// conflict with global browser properties.
|
|
41
|
+
const protectedProperties = (() =>
|
|
42
|
+
Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(
|
|
43
|
+
(prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',
|
|
44
|
+
))();
|
|
45
|
+
|
|
46
|
+
function installEnv(...args: any[]) {
|
|
47
|
+
// Sets up global browser environment
|
|
48
|
+
// Extract options from args
|
|
49
|
+
const properties = args.filter((arg: any) => Array.isArray(arg))[0];
|
|
50
|
+
const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];
|
|
51
|
+
|
|
52
|
+
// Create window object
|
|
53
|
+
const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));
|
|
54
|
+
|
|
55
|
+
// Get all global browser properties
|
|
56
|
+
Object.getOwnPropertyNames(window)
|
|
57
|
+
|
|
58
|
+
// Remove protected properties
|
|
59
|
+
.filter((prop) => !protectedProperties.includes(prop))
|
|
60
|
+
|
|
61
|
+
// If we're only applying specific required properties remove everything else
|
|
62
|
+
.filter((prop) => !(properties && properties.indexOf(prop) === -1))
|
|
63
|
+
.filter((prop) => {
|
|
64
|
+
switch (prop) {
|
|
65
|
+
case 'undefined':
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Copy what's left to the Node.js global scope
|
|
72
|
+
.forEach((prop) => {
|
|
73
|
+
// console.debug(`define globalThis.${prop}`);
|
|
74
|
+
Object.defineProperty(globalThis, prop, {
|
|
75
|
+
configurable: true,
|
|
76
|
+
get: () => window[prop as keyof Window] as any,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return window;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
installEnv({ url: 'http://localhost' });
|
|
84
|
+
return true;
|
|
85
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { polyfillCrypto } from './server/polyfillCrypto';
|
|
2
|
+
export { polyfillFetch } from './server/polyfillFetch';
|
|
3
|
+
export { polyfillJsDom } from './server/polyfillJsDom';
|
|
4
|
+
export { polyfillBrowser } from './server/polyfillBrowser';
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import { get } from '../objects/get';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* render template like js template string
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @example
|
|
7
|
+
* renderTemplate('My name is ${name}',{name:'wener'})
|
|
8
|
+
* // 'My name is wener'
|
|
7
9
|
*
|
|
10
|
+
* @param match `js` for `${name}`, common for `{{name}}`
|
|
8
11
|
*/
|
|
9
12
|
export function renderTemplate(
|
|
10
13
|
template: string,
|
|
11
|
-
data: ((v: string) => any) | object,
|
|
14
|
+
data: ((v: string) => any) | object | undefined,
|
|
12
15
|
match: 'js' | 'common' | RegExp = 'js',
|
|
13
16
|
) {
|
|
14
17
|
let getter: Function;
|
|
15
|
-
if (
|
|
18
|
+
if (!data) {
|
|
19
|
+
// todo warning in dev
|
|
20
|
+
getter = () => '';
|
|
21
|
+
} else if (typeof data === 'function') {
|
|
16
22
|
getter = data;
|
|
17
23
|
} else {
|
|
18
24
|
getter = (v: string) => get(data, v);
|
|
19
25
|
}
|
|
20
26
|
if (typeof match === 'string') {
|
|
21
|
-
match = Matches[match] || Matches
|
|
27
|
+
match = Matches[match] || Matches.js;
|
|
22
28
|
}
|
|
23
29
|
return template.replace(match, (_, g) => {
|
|
24
30
|
return getter(g.trim());
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
const Matches = {
|
|
34
|
+
const Matches: Record<string, RegExp> = {
|
|
29
35
|
js: /\${(.*?)}/g,
|
|
30
36
|
common: /{{(.*?)}}/g,
|
|
31
37
|
};
|
package/src/typedoc.ts
ADDED
package/tsconfig.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function createLazyPromise() {
|
|
2
|
-
const holder = {
|
|
3
|
-
resolve(_) {
|
|
4
|
-
throw new Error("pending resolve");
|
|
5
|
-
},
|
|
6
|
-
reject(_) {
|
|
7
|
-
throw new Error("pending reject");
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
return Object.assign(
|
|
11
|
-
new Promise((resolve, reject) => {
|
|
12
|
-
holder.reject = reject;
|
|
13
|
-
holder.resolve = resolve;
|
|
14
|
-
}),
|
|
15
|
-
{
|
|
16
|
-
resolve(v) {
|
|
17
|
-
holder.resolve(v);
|
|
18
|
-
},
|
|
19
|
-
reject(v) {
|
|
20
|
-
holder.resolve(v);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { createLazyPromise };
|
|
27
|
-
//# sourceMappingURL=LazyPromise.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LazyPromise.js","sources":["../../src/asyncs/LazyPromise.ts"],"sourcesContent":["export type LazyPromise<T> = Promise<T> & {\n reject(e: any): void;\n resolve(v?: T | PromiseLike<T>): void;\n};\n\nexport function createLazyPromise<T = any>(): LazyPromise<T> {\n const holder = {\n resolve(_: any): void {\n throw new Error('pending resolve');\n },\n reject(_: any): void {\n throw new Error('pending reject');\n },\n };\n return Object.assign(\n new Promise<T>((resolve, reject) => {\n holder.reject = reject;\n holder.resolve = resolve;\n }),\n {\n resolve(v: any) {\n holder.resolve(v);\n },\n reject(v: any) {\n holder.resolve(v);\n },\n },\n );\n}\n"],"names":[],"mappings":"AAKO,SAAS,iBAA6C,GAAA;AAC3D,EAAA,MAAM,MAAS,GAAA;AAAA,IACb,QAAQ,CAAc,EAAA;AACpB,MAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAAA;AAAA,KACnC;AAAA,IACA,OAAO,CAAc,EAAA;AACnB,MAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,KAClC;AAAA,GACF,CAAA;AACA,EAAA,OAAO,MAAO,CAAA,MAAA;AAAA,IACZ,IAAI,OAAA,CAAW,CAAC,OAAA,EAAS,MAAW,KAAA;AAClC,MAAA,MAAA,CAAO,MAAS,GAAA,MAAA,CAAA;AAChB,MAAA,MAAA,CAAO,OAAU,GAAA,OAAA,CAAA;AAAA,KAClB,CAAA;AAAA,IACD;AAAA,MACE,QAAQ,CAAQ,EAAA;AACd,QAAA,MAAA,CAAO,QAAQ,CAAC,CAAA,CAAA;AAAA,OAClB;AAAA,MACA,OAAO,CAAQ,EAAA;AACb,QAAA,MAAA,CAAO,QAAQ,CAAC,CAAA,CAAA;AAAA,OAClB;AAAA,KACF;AAAA,GACF,CAAA;AACF;;;;"}
|
package/lib/crypto/hex.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.js","sources":["../../src/crypto/hex.ts"],"sourcesContent":["export function hex(s: Uint8Array | ArrayBuffer) {\n return Array.from(new Uint8Array(s))\n .map((v) => v.toString(16).padStart(2, '0'))\n .join('');\n}\n"],"names":[],"mappings":"AAAO,SAAS,IAAI,CAA6B,EAAA;AAC/C,EAAO,OAAA,KAAA,CAAM,KAAK,IAAI,UAAA,CAAW,CAAC,CAAC,CAAA,CAChC,IAAI,CAAC,CAAA,KAAM,EAAE,QAAS,CAAA,EAAE,EAAE,QAAS,CAAA,CAAA,EAAG,GAAG,CAAC,CAAA,CAC1C,KAAK,EAAE,CAAA,CAAA;AACZ;;;;"}
|
package/lib/server/polyfill.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polyfill.js","sources":["../../src/server/polyfill.ts"],"sourcesContent":["export async function polyfill() {\n if (!('crypto' in globalThis)) {\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto;\n }\n}\n"],"names":[],"mappings":"AAAA,eAAsB,QAAW,GAAA;AAC/B,EAAI,IAAA,EAAE,YAAY,UAAa,CAAA,EAAA;AAC7B,IAAC,UAAmB,CAAA,MAAA,GAAA,CAAU,MAAM,OAAO,aAAgB,CAAA,EAAA,SAAA,CAAA;AAAA,GAC7D;AACF;;;;"}
|
package/lib/shim/urljoin.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
function urljoin(...args) {
|
|
2
|
-
if (Array.isArray(args[0])) {
|
|
3
|
-
return normalize(args[0]);
|
|
4
|
-
} else {
|
|
5
|
-
return normalize(args);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
function normalize(strArray) {
|
|
9
|
-
const resultArray = [];
|
|
10
|
-
if (strArray.length === 0) {
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
if (typeof strArray[0] !== "string") {
|
|
14
|
-
throw new TypeError("Url must be a string. Received " + strArray[0]);
|
|
15
|
-
}
|
|
16
|
-
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
|
|
17
|
-
const first = strArray.shift();
|
|
18
|
-
strArray[0] = first + strArray[0];
|
|
19
|
-
}
|
|
20
|
-
if (strArray[0].match(/^file:\/\/\//)) {
|
|
21
|
-
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
|
|
22
|
-
} else {
|
|
23
|
-
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
|
|
24
|
-
}
|
|
25
|
-
for (let i = 0; i < strArray.length; i++) {
|
|
26
|
-
let component = strArray[i];
|
|
27
|
-
if (typeof component !== "string") {
|
|
28
|
-
throw new TypeError("Url must be a string. Received " + component);
|
|
29
|
-
}
|
|
30
|
-
if (component === "") {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (i > 0) {
|
|
34
|
-
component = component.replace(/^[\/]+/, "");
|
|
35
|
-
}
|
|
36
|
-
if (i < strArray.length - 1) {
|
|
37
|
-
component = component.replace(/[\/]+$/, "");
|
|
38
|
-
} else {
|
|
39
|
-
component = component.replace(/[\/]+$/, "/");
|
|
40
|
-
}
|
|
41
|
-
resultArray.push(component);
|
|
42
|
-
}
|
|
43
|
-
let str = resultArray.join("/");
|
|
44
|
-
str = str.replace(/\/(\?|&|#[^!])/g, "$1");
|
|
45
|
-
const parts = str.split("?");
|
|
46
|
-
str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
|
|
47
|
-
return str;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { urljoin };
|
|
51
|
-
//# sourceMappingURL=urljoin.js.map
|
package/lib/shim/urljoin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"urljoin.js","sources":["../../src/shim/urljoin.ts"],"sourcesContent":["export function urljoin(...strArray: string[]): string;\nexport function urljoin(strArray: string[]): string;\n\n/**\n * @see {@link https://github.com/jfromaniello/url-join}\n */\nexport function urljoin(...args: string[] | [string[]]): string {\n if (Array.isArray(args[0])) {\n return normalize(args[0]);\n } else {\n return normalize(args as any);\n }\n}\n\nfunction normalize(strArray: string[]) {\n const resultArray: string[] = [];\n if (strArray.length === 0) {\n return '';\n }\n\n if (typeof strArray[0] !== 'string') {\n throw new TypeError('Url must be a string. Received ' + strArray[0]);\n }\n\n // If the first part is a plain protocol, we combine it with the next part.\n if (strArray[0].match(/^[^/:]+:\\/*$/) && strArray.length > 1) {\n const first = strArray.shift();\n strArray[0] = first + strArray[0];\n }\n\n // There must be two or three slashes in the file protocol, two slashes in anything else.\n if (strArray[0].match(/^file:\\/\\/\\//)) {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, '$1:///');\n } else {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, '$1://');\n }\n\n for (let i = 0; i < strArray.length; i++) {\n let component = strArray[i];\n\n if (typeof component !== 'string') {\n throw new TypeError('Url must be a string. Received ' + component);\n }\n\n if (component === '') {\n continue;\n }\n\n if (i > 0) {\n // Removing the starting slashes for each component but the first.\n component = component.replace(/^[\\/]+/, '');\n }\n if (i < strArray.length - 1) {\n // Removing the ending slashes for each component but the last.\n component = component.replace(/[\\/]+$/, '');\n } else {\n // For the last component we will combine multiple slashes to a single one.\n component = component.replace(/[\\/]+$/, '/');\n }\n\n resultArray.push(component);\n }\n\n let str = resultArray.join('/');\n // Each input component is now separated by a single slash except the possible first plain protocol part.\n\n // remove trailing slash before parameters or hash\n str = str.replace(/\\/(\\?|&|#[^!])/g, '$1');\n\n // replace ? in parameters with &\n const parts = str.split('?');\n str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');\n\n return str;\n}\n"],"names":[],"mappings":"AAMO,SAAS,WAAW,IAAqC,EAAA;AAC9D,EAAA,IAAI,KAAM,CAAA,OAAA,CAAQ,IAAK,CAAA,CAAA,CAAE,CAAG,EAAA;AAC1B,IAAO,OAAA,SAAA,CAAU,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,GACnB,MAAA;AACL,IAAA,OAAO,UAAU,IAAW,CAAA,CAAA;AAAA,GAC9B;AACF,CAAA;AAEA,SAAS,UAAU,QAAoB,EAA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IAAI,IAAI,CAAG,EAAA;AAET,MAAY,SAAA,GAAA,SAAA,CAAU,OAAQ,CAAA,QAAA,EAAU,EAAE,CAAA,CAAA;AAAA,KAC5C;AACA,IAAI,IAAA,CAAA,GAAI,QAAS,CAAA,MAAA,GAAS,CAAG,EAAA;AAE3B,MAAY,SAAA,GAAA,SAAA,CAAU,OAAQ,CAAA,QAAA,EAAU,EAAE,CAAA,CAAA;AAAA,KACrC,MAAA;AAEL,MAAY,SAAA,GAAA,SAAA,CAAU,OAAQ,CAAA,QAAA,EAAU,GAAG,CAAA,CAAA;AAAA,KAC7C;AAEA,IAAA,WAAA,CAAY,KAAK,SAAS,CAAA,CAAA;AAAA,GAC5B;AAEA,EAAI,IAAA,GAAA,GAAM,WAAY,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA;AAI9B,EAAM,GAAA,GAAA,GAAA,CAAI,OAAQ,CAAA,iBAAA,EAAmB,IAAI,CAAA,CAAA;AAGzC,EAAM,MAAA,KAAA,GAAQ,GAAI,CAAA,KAAA,CAAM,GAAG,CAAA,CAAA;AAC3B,EAAM,GAAA,GAAA,KAAA,CAAM,KAAM,EAAA,IAAK,KAAM,CAAA,MAAA,GAAS,IAAI,GAAM,GAAA,EAAA,CAAA,GAAM,KAAM,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA;AAEpE,EAAO,OAAA,GAAA,CAAA;AACT;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dequal.js","sources":["../../src/validations/dequal.ts"],"sourcesContent":["const has = Object.prototype.hasOwnProperty;\nconst hasElementType = typeof Element !== 'undefined';\n\nfunction find(iter: any, tar: any, key?: any) {\n for (key of iter.keys()) {\n if (dequal(key, tar)) return key;\n }\n}\n\n/**\n * deep equal - support react, dom, Date, RegExp, Array, ArrayBuffer, Set, Map, Object\n * @see {@link https://github.com/lukeed/dequal/blob/master/src/lite.js dequal/src/lite.js}\n * @see {@link https://github.com/FormidableLabs/react-fast-compare/blob/master/index.js react-fast-compare/index.js}\n */\nexport function dequal(foo: any, bar: any) {\n let ctor, len, tmp;\n if (foo === bar) return true;\n\n if (foo && bar && (ctor = foo.constructor) === bar.constructor) {\n if (ctor === Date) return foo.getTime() === bar.getTime();\n if (ctor === RegExp) return foo.toString() === bar.toString();\n\n if (ctor === Array) {\n if ((len = foo.length) === bar.length) {\n while (len-- && dequal(foo[len], bar[len]));\n }\n return len === -1;\n }\n\n if (ctor === Set) {\n if (foo.size !== bar.size) {\n return false;\n }\n for (len of foo) {\n tmp = len;\n if (tmp && typeof tmp === 'object') {\n tmp = find(bar, tmp);\n if (!tmp) return false;\n }\n if (!bar.has(tmp)) return false;\n }\n return true;\n }\n\n if (ctor === Map) {\n if (foo.size !== bar.size) {\n return false;\n }\n for (len of foo) {\n tmp = len[0];\n if (tmp && typeof tmp === 'object') {\n tmp = find(bar, tmp);\n if (!tmp) return false;\n }\n if (!dequal(len[1], bar.get(tmp))) {\n return false;\n }\n }\n return true;\n }\n\n if (ctor === ArrayBuffer) {\n foo = new Uint8Array(foo);\n bar = new Uint8Array(bar);\n } else if (ctor === DataView) {\n if ((len = foo.byteLength) === bar.byteLength) {\n while (len-- && foo.getInt8(len) === bar.getInt8(len));\n }\n return len === -1;\n }\n\n if (ArrayBuffer.isView(foo)) {\n if ((len = foo.byteLength) === bar.byteLength) {\n while (len-- && (foo as any)[len] === bar[len]);\n }\n return len === -1;\n }\n\n // react & dom\n if (hasElementType && foo instanceof Element) return false;\n\n if (!ctor || typeof foo === 'object') {\n len = 0;\n for (ctor in foo) {\n if ((ctor === '_owner' || ctor === '__v' || ctor === '__o') && foo.$$typeof) {\n // React-specific: avoid traversing React elements' _owner\n // Preact-specific: avoid traversing Preact elements' __v and __o\n // __v = $_original / $_vnode\n // __o = $_owner\n // These properties contain circular references and are not needed when\n // comparing the actual elements (and not their owners)\n // .$$typeof and ._store on just reasonable markers of elements\n\n continue;\n }\n\n if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;\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IAAI,CAAA;AAAG,UAAO,OAAA,KAAA,CAAA;AACjE,QAAI,IAAA,EAAE,QAAQ,GAAQ,CAAA,IAAA,CAAC,OAAO,GAAI,CAAA,IAAA,CAAA,EAAO,IAAI,IAAK,CAAA,CAAA;AAAG,UAAO,OAAA,KAAA,CAAA;AAAA,OAC9D;AACA,MAAA,OAAO,MAAO,CAAA,IAAA,CAAK,GAAG,CAAA,CAAE,MAAW,KAAA,GAAA,CAAA;AAAA,KACrC;AAAA,GACF;AAEA,EAAO,OAAA,GAAA,KAAQ,OAAO,GAAQ,KAAA,GAAA,CAAA;AAChC;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shallow.js","sources":["../../src/validations/shallow.ts"],"sourcesContent":["/**\n * shallow compare - support object, array\n *\n * @see {@link https://github.com/pmndrs/zustand/blob/main/src/shallow.ts zustand/src/shallow.ts}\n */\nexport function shallow<T, U>(objA: T, objB: U) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n return false;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof U])\n ) {\n return false;\n }\n }\n return true;\n}\n"],"names":[],"mappings":"AAKgB,SAAA,OAAA,CAAc,MAAS,IAAS,EAAA;AAC9C,EAAA,IAAI,MAAO,CAAA,EAAA,CAAG,IAAM,EAAA,IAAI,CAAG,EAAA;AACzB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACA,EAAI,IAAA,OAAO,SAAS,QAAY,IAAA,IAAA,KAAS,QAAQ,OAAO,IAAA,KAAS,QAAY,IAAA,IAAA,KAAS,IAAM,EAAA;AAC1F,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC9B,EAAA,IAAI,MAAM,MAAW,KAAA,MAAA,CAAO,IAAK,CAAA,IAAI,EAAE,MAAQ,EAAA;AAC7C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,CAAM,QAAQ,CAAK,EAAA,EAAA;AACrC,IAAA,IACE,CAAC,MAAO,CAAA,SAAA,CAAU,eAAe,IAAK,CAAA,IAAA,EAAM,MAAM,CAAY,CAAA,CAAA,IAC9D,CAAC,MAAA,CAAO,GAAG,IAAK,CAAA,KAAA,CAAM,KAAgB,IAAK,CAAA,KAAA,CAAM,GAAc,CAC/D,EAAA;AACA,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AACA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|