mol_vary 0.0.88 → 0.0.90
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/node.d.ts +3 -6
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +42 -75
- package/node.js.map +1 -1
- package/node.mjs +42 -75
- package/node.test.js +47 -103
- package/node.test.js.map +1 -1
- package/package.json +2 -3
- package/web.d.ts +2 -6
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +37 -75
- package/web.js.map +1 -1
- package/web.mjs +37 -75
- package/web.test.js +5 -28
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
|
@@ -28,6 +28,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
28
28
|
var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
|
|
29
29
|
$.$$ = $
|
|
30
30
|
|
|
31
|
+
;
|
|
32
|
+
"use strict";
|
|
33
|
+
var $;
|
|
34
|
+
(function ($) {
|
|
35
|
+
function $mol_fail(error) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
$.$mol_fail = $mol_fail;
|
|
39
|
+
})($ || ($ = {}));
|
|
40
|
+
|
|
31
41
|
;
|
|
32
42
|
"use strict";
|
|
33
43
|
var $;
|
|
@@ -50,16 +60,6 @@ var $;
|
|
|
50
60
|
$.$mol_bigint_encode = $mol_bigint_encode;
|
|
51
61
|
})($ || ($ = {}));
|
|
52
62
|
|
|
53
|
-
;
|
|
54
|
-
"use strict";
|
|
55
|
-
var $;
|
|
56
|
-
(function ($) {
|
|
57
|
-
function $mol_fail(error) {
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
$.$mol_fail = $mol_fail;
|
|
61
|
-
})($ || ($ = {}));
|
|
62
|
-
|
|
63
63
|
;
|
|
64
64
|
"use strict";
|
|
65
65
|
var $;
|
|
@@ -160,59 +160,6 @@ var $;
|
|
|
160
160
|
$.$mol_charset_decode = $mol_charset_decode;
|
|
161
161
|
})($ || ($ = {}));
|
|
162
162
|
|
|
163
|
-
;
|
|
164
|
-
"use strict";
|
|
165
|
-
var $;
|
|
166
|
-
(function ($) {
|
|
167
|
-
function $mol_charset_decode_from(buffer, from, count) {
|
|
168
|
-
const codes = [];
|
|
169
|
-
let pos = from;
|
|
170
|
-
while (pos < buffer.length && codes.length < count) {
|
|
171
|
-
const byte1 = buffer[pos++];
|
|
172
|
-
if (byte1 <= 0x7F) {
|
|
173
|
-
codes.push(byte1);
|
|
174
|
-
}
|
|
175
|
-
else if ((byte1 & 0xE0) === 0xC0) {
|
|
176
|
-
if (pos >= buffer.length)
|
|
177
|
-
break;
|
|
178
|
-
const byte2 = buffer[pos++];
|
|
179
|
-
const code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
|
|
180
|
-
codes.push(code);
|
|
181
|
-
}
|
|
182
|
-
else if ((byte1 & 0xF0) === 0xE0) {
|
|
183
|
-
if (pos + 1 >= buffer.length)
|
|
184
|
-
break;
|
|
185
|
-
const byte2 = buffer[pos++];
|
|
186
|
-
const byte3 = buffer[pos++];
|
|
187
|
-
const code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
|
|
188
|
-
codes.push(code);
|
|
189
|
-
}
|
|
190
|
-
else if ((byte1 & 0xF8) === 0xF0) {
|
|
191
|
-
if (pos + 2 >= buffer.length)
|
|
192
|
-
break;
|
|
193
|
-
const byte2 = buffer[pos++];
|
|
194
|
-
const byte3 = buffer[pos++];
|
|
195
|
-
const byte4 = buffer[pos++];
|
|
196
|
-
let code = ((byte1 & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
|
|
197
|
-
if (code > 0xFFFF) {
|
|
198
|
-
code -= 0x10000;
|
|
199
|
-
const hi = 0xD800 + (code >> 10);
|
|
200
|
-
const lo = 0xDC00 + (code & 0x3FF);
|
|
201
|
-
codes.push(hi, lo);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
codes.push(code);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
codes.push(0xFFFD);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return [String.fromCharCode(...codes), pos - from];
|
|
212
|
-
}
|
|
213
|
-
$.$mol_charset_decode_from = $mol_charset_decode_from;
|
|
214
|
-
})($ || ($ = {}));
|
|
215
|
-
|
|
216
163
|
;
|
|
217
164
|
"use strict";
|
|
218
165
|
var $;
|
|
@@ -549,6 +496,8 @@ var $;
|
|
|
549
496
|
"use strict";
|
|
550
497
|
var $;
|
|
551
498
|
(function ($) {
|
|
499
|
+
if (!Symbol.dispose)
|
|
500
|
+
Symbol.dispose = Symbol('Symbol.dispose');
|
|
552
501
|
class $mol_object2 {
|
|
553
502
|
static $ = $;
|
|
554
503
|
[Symbol.toStringTag];
|
|
@@ -581,6 +530,9 @@ var $;
|
|
|
581
530
|
}
|
|
582
531
|
destructor() { }
|
|
583
532
|
static destructor() { }
|
|
533
|
+
[Symbol.dispose]() {
|
|
534
|
+
this.destructor();
|
|
535
|
+
}
|
|
584
536
|
toString() {
|
|
585
537
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
586
538
|
}
|
|
@@ -2397,8 +2349,21 @@ var $;
|
|
|
2397
2349
|
const release = (size) => {
|
|
2398
2350
|
capacity -= size;
|
|
2399
2351
|
};
|
|
2400
|
-
const
|
|
2401
|
-
if (val < $mol_vary_len.L1)
|
|
2352
|
+
const calc_size = (val) => {
|
|
2353
|
+
if (val < $mol_vary_len.L1)
|
|
2354
|
+
return 1;
|
|
2355
|
+
if (val < 2 ** 8)
|
|
2356
|
+
return 2;
|
|
2357
|
+
if (val < 2 ** 16)
|
|
2358
|
+
return 3;
|
|
2359
|
+
if (val < 2 ** 32)
|
|
2360
|
+
return 5;
|
|
2361
|
+
if (val < 2n ** 64n)
|
|
2362
|
+
return 9;
|
|
2363
|
+
return $mol_fail(new Error('Too large number'));
|
|
2364
|
+
};
|
|
2365
|
+
const dump_unum = (tip, val, max = val) => {
|
|
2366
|
+
if (max < $mol_vary_len.L1) {
|
|
2402
2367
|
this.array[pos++] = tip | Number(val);
|
|
2403
2368
|
release(8);
|
|
2404
2369
|
return;
|
|
@@ -2408,24 +2373,24 @@ var $;
|
|
|
2408
2373
|
if (offset !== undefined)
|
|
2409
2374
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2410
2375
|
}
|
|
2411
|
-
if (
|
|
2376
|
+
if (max < 2 ** 8) {
|
|
2412
2377
|
this.array[pos++] = tip | $mol_vary_len.L1;
|
|
2413
2378
|
this.array[pos++] = Number(val);
|
|
2414
2379
|
release(7);
|
|
2415
2380
|
}
|
|
2416
|
-
else if (
|
|
2381
|
+
else if (max < 2 ** 16) {
|
|
2417
2382
|
this.array[pos++] = tip | $mol_vary_len.L2;
|
|
2418
2383
|
this.buffer.setUint16(pos, Number(val), true);
|
|
2419
2384
|
pos += 2;
|
|
2420
2385
|
release(6);
|
|
2421
2386
|
}
|
|
2422
|
-
else if (
|
|
2387
|
+
else if (max < 2 ** 32) {
|
|
2423
2388
|
this.array[pos++] = tip | $mol_vary_len.L4;
|
|
2424
2389
|
this.buffer.setUint32(pos, Number(val), true);
|
|
2425
2390
|
pos += 4;
|
|
2426
2391
|
release(4);
|
|
2427
2392
|
}
|
|
2428
|
-
else if (
|
|
2393
|
+
else if (max < 2n ** 64n) {
|
|
2429
2394
|
this.array[pos++] = tip | $mol_vary_len.L8;
|
|
2430
2395
|
this.buffer.setBigUint64(pos, BigInt(val), true);
|
|
2431
2396
|
pos += 8;
|
|
@@ -2496,11 +2461,13 @@ var $;
|
|
|
2496
2461
|
const offset = offsets.get(val);
|
|
2497
2462
|
if (offset !== undefined)
|
|
2498
2463
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2464
|
+
const len_max = val.length * 3;
|
|
2465
|
+
const len_size = calc_size(len_max);
|
|
2466
|
+
acquire(len_max);
|
|
2467
|
+
const len = $mol_charset_encode_to(val, this.array, pos + len_size);
|
|
2468
|
+
dump_unum($mol_vary_tip.text, len, len_max);
|
|
2502
2469
|
pos += len;
|
|
2503
|
-
release(
|
|
2470
|
+
release(len_max - len);
|
|
2504
2471
|
offsets.set(val, offsets.size);
|
|
2505
2472
|
return;
|
|
2506
2473
|
};
|
|
@@ -2706,8 +2673,8 @@ var $;
|
|
|
2706
2673
|
};
|
|
2707
2674
|
const read_text = (kind) => {
|
|
2708
2675
|
const len = read_unum(kind);
|
|
2709
|
-
const
|
|
2710
|
-
pos +=
|
|
2676
|
+
const text = $mol_charset_decode(new Uint8Array(array.buffer, array.byteOffset + pos, len));
|
|
2677
|
+
pos += len;
|
|
2711
2678
|
stream.push(text);
|
|
2712
2679
|
return text;
|
|
2713
2680
|
};
|
package/node.test.js
CHANGED
|
@@ -19,6 +19,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
19
19
|
var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
|
|
20
20
|
$.$$ = $
|
|
21
21
|
|
|
22
|
+
;
|
|
23
|
+
"use strict";
|
|
24
|
+
var $;
|
|
25
|
+
(function ($) {
|
|
26
|
+
function $mol_fail(error) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
$.$mol_fail = $mol_fail;
|
|
30
|
+
})($ || ($ = {}));
|
|
31
|
+
|
|
22
32
|
;
|
|
23
33
|
"use strict";
|
|
24
34
|
var $;
|
|
@@ -41,16 +51,6 @@ var $;
|
|
|
41
51
|
$.$mol_bigint_encode = $mol_bigint_encode;
|
|
42
52
|
})($ || ($ = {}));
|
|
43
53
|
|
|
44
|
-
;
|
|
45
|
-
"use strict";
|
|
46
|
-
var $;
|
|
47
|
-
(function ($) {
|
|
48
|
-
function $mol_fail(error) {
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
$.$mol_fail = $mol_fail;
|
|
52
|
-
})($ || ($ = {}));
|
|
53
|
-
|
|
54
54
|
;
|
|
55
55
|
"use strict";
|
|
56
56
|
var $;
|
|
@@ -151,59 +151,6 @@ var $;
|
|
|
151
151
|
$.$mol_charset_decode = $mol_charset_decode;
|
|
152
152
|
})($ || ($ = {}));
|
|
153
153
|
|
|
154
|
-
;
|
|
155
|
-
"use strict";
|
|
156
|
-
var $;
|
|
157
|
-
(function ($) {
|
|
158
|
-
function $mol_charset_decode_from(buffer, from, count) {
|
|
159
|
-
const codes = [];
|
|
160
|
-
let pos = from;
|
|
161
|
-
while (pos < buffer.length && codes.length < count) {
|
|
162
|
-
const byte1 = buffer[pos++];
|
|
163
|
-
if (byte1 <= 0x7F) {
|
|
164
|
-
codes.push(byte1);
|
|
165
|
-
}
|
|
166
|
-
else if ((byte1 & 0xE0) === 0xC0) {
|
|
167
|
-
if (pos >= buffer.length)
|
|
168
|
-
break;
|
|
169
|
-
const byte2 = buffer[pos++];
|
|
170
|
-
const code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
|
|
171
|
-
codes.push(code);
|
|
172
|
-
}
|
|
173
|
-
else if ((byte1 & 0xF0) === 0xE0) {
|
|
174
|
-
if (pos + 1 >= buffer.length)
|
|
175
|
-
break;
|
|
176
|
-
const byte2 = buffer[pos++];
|
|
177
|
-
const byte3 = buffer[pos++];
|
|
178
|
-
const code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
|
|
179
|
-
codes.push(code);
|
|
180
|
-
}
|
|
181
|
-
else if ((byte1 & 0xF8) === 0xF0) {
|
|
182
|
-
if (pos + 2 >= buffer.length)
|
|
183
|
-
break;
|
|
184
|
-
const byte2 = buffer[pos++];
|
|
185
|
-
const byte3 = buffer[pos++];
|
|
186
|
-
const byte4 = buffer[pos++];
|
|
187
|
-
let code = ((byte1 & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
|
|
188
|
-
if (code > 0xFFFF) {
|
|
189
|
-
code -= 0x10000;
|
|
190
|
-
const hi = 0xD800 + (code >> 10);
|
|
191
|
-
const lo = 0xDC00 + (code & 0x3FF);
|
|
192
|
-
codes.push(hi, lo);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
codes.push(code);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
codes.push(0xFFFD);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return [String.fromCharCode(...codes), pos - from];
|
|
203
|
-
}
|
|
204
|
-
$.$mol_charset_decode_from = $mol_charset_decode_from;
|
|
205
|
-
})($ || ($ = {}));
|
|
206
|
-
|
|
207
154
|
;
|
|
208
155
|
"use strict";
|
|
209
156
|
var $;
|
|
@@ -540,6 +487,8 @@ var $;
|
|
|
540
487
|
"use strict";
|
|
541
488
|
var $;
|
|
542
489
|
(function ($) {
|
|
490
|
+
if (!Symbol.dispose)
|
|
491
|
+
Symbol.dispose = Symbol('Symbol.dispose');
|
|
543
492
|
class $mol_object2 {
|
|
544
493
|
static $ = $;
|
|
545
494
|
[Symbol.toStringTag];
|
|
@@ -572,6 +521,9 @@ var $;
|
|
|
572
521
|
}
|
|
573
522
|
destructor() { }
|
|
574
523
|
static destructor() { }
|
|
524
|
+
[Symbol.dispose]() {
|
|
525
|
+
this.destructor();
|
|
526
|
+
}
|
|
575
527
|
toString() {
|
|
576
528
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
577
529
|
}
|
|
@@ -2388,8 +2340,21 @@ var $;
|
|
|
2388
2340
|
const release = (size) => {
|
|
2389
2341
|
capacity -= size;
|
|
2390
2342
|
};
|
|
2391
|
-
const
|
|
2392
|
-
if (val < $mol_vary_len.L1)
|
|
2343
|
+
const calc_size = (val) => {
|
|
2344
|
+
if (val < $mol_vary_len.L1)
|
|
2345
|
+
return 1;
|
|
2346
|
+
if (val < 2 ** 8)
|
|
2347
|
+
return 2;
|
|
2348
|
+
if (val < 2 ** 16)
|
|
2349
|
+
return 3;
|
|
2350
|
+
if (val < 2 ** 32)
|
|
2351
|
+
return 5;
|
|
2352
|
+
if (val < 2n ** 64n)
|
|
2353
|
+
return 9;
|
|
2354
|
+
return $mol_fail(new Error('Too large number'));
|
|
2355
|
+
};
|
|
2356
|
+
const dump_unum = (tip, val, max = val) => {
|
|
2357
|
+
if (max < $mol_vary_len.L1) {
|
|
2393
2358
|
this.array[pos++] = tip | Number(val);
|
|
2394
2359
|
release(8);
|
|
2395
2360
|
return;
|
|
@@ -2399,24 +2364,24 @@ var $;
|
|
|
2399
2364
|
if (offset !== undefined)
|
|
2400
2365
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2401
2366
|
}
|
|
2402
|
-
if (
|
|
2367
|
+
if (max < 2 ** 8) {
|
|
2403
2368
|
this.array[pos++] = tip | $mol_vary_len.L1;
|
|
2404
2369
|
this.array[pos++] = Number(val);
|
|
2405
2370
|
release(7);
|
|
2406
2371
|
}
|
|
2407
|
-
else if (
|
|
2372
|
+
else if (max < 2 ** 16) {
|
|
2408
2373
|
this.array[pos++] = tip | $mol_vary_len.L2;
|
|
2409
2374
|
this.buffer.setUint16(pos, Number(val), true);
|
|
2410
2375
|
pos += 2;
|
|
2411
2376
|
release(6);
|
|
2412
2377
|
}
|
|
2413
|
-
else if (
|
|
2378
|
+
else if (max < 2 ** 32) {
|
|
2414
2379
|
this.array[pos++] = tip | $mol_vary_len.L4;
|
|
2415
2380
|
this.buffer.setUint32(pos, Number(val), true);
|
|
2416
2381
|
pos += 4;
|
|
2417
2382
|
release(4);
|
|
2418
2383
|
}
|
|
2419
|
-
else if (
|
|
2384
|
+
else if (max < 2n ** 64n) {
|
|
2420
2385
|
this.array[pos++] = tip | $mol_vary_len.L8;
|
|
2421
2386
|
this.buffer.setBigUint64(pos, BigInt(val), true);
|
|
2422
2387
|
pos += 8;
|
|
@@ -2487,11 +2452,13 @@ var $;
|
|
|
2487
2452
|
const offset = offsets.get(val);
|
|
2488
2453
|
if (offset !== undefined)
|
|
2489
2454
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2455
|
+
const len_max = val.length * 3;
|
|
2456
|
+
const len_size = calc_size(len_max);
|
|
2457
|
+
acquire(len_max);
|
|
2458
|
+
const len = $mol_charset_encode_to(val, this.array, pos + len_size);
|
|
2459
|
+
dump_unum($mol_vary_tip.text, len, len_max);
|
|
2493
2460
|
pos += len;
|
|
2494
|
-
release(
|
|
2461
|
+
release(len_max - len);
|
|
2495
2462
|
offsets.set(val, offsets.size);
|
|
2496
2463
|
return;
|
|
2497
2464
|
};
|
|
@@ -2697,8 +2664,8 @@ var $;
|
|
|
2697
2664
|
};
|
|
2698
2665
|
const read_text = (kind) => {
|
|
2699
2666
|
const len = read_unum(kind);
|
|
2700
|
-
const
|
|
2701
|
-
pos +=
|
|
2667
|
+
const text = $mol_charset_decode(new Uint8Array(array.buffer, array.byteOffset + pos, len));
|
|
2668
|
+
pos += len;
|
|
2702
2669
|
stream.push(text);
|
|
2703
2670
|
return text;
|
|
2704
2671
|
};
|
|
@@ -4555,32 +4522,6 @@ var $;
|
|
|
4555
4522
|
});
|
|
4556
4523
|
})($ || ($ = {}));
|
|
4557
4524
|
|
|
4558
|
-
;
|
|
4559
|
-
"use strict";
|
|
4560
|
-
var $;
|
|
4561
|
-
(function ($) {
|
|
4562
|
-
$mol_test({
|
|
4563
|
-
'encode empty'() {
|
|
4564
|
-
$mol_assert_equal($mol_charset_decode_from(new Uint8Array([]), 0, 0), ['', 0]);
|
|
4565
|
-
},
|
|
4566
|
-
'encode 1 octet'() {
|
|
4567
|
-
$mol_assert_equal($mol_charset_decode_from(new Uint8Array([0x46]), 0, 1), ['F', 1]);
|
|
4568
|
-
},
|
|
4569
|
-
'encode 2 octet'() {
|
|
4570
|
-
$mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xd0, 0x91]), 0, 1), ['Б', 2]);
|
|
4571
|
-
},
|
|
4572
|
-
'encode 3 octet'() {
|
|
4573
|
-
$mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xe0, 0xa4, 0xb9]), 0, 1), ['ह', 3]);
|
|
4574
|
-
},
|
|
4575
|
-
'encode 4 octet'() {
|
|
4576
|
-
$mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xf0, 0x90, 0x8d, 0x88]), 0, 1), ['𐍈', 4]);
|
|
4577
|
-
},
|
|
4578
|
-
'encode surrogate pair'() {
|
|
4579
|
-
$mol_assert_equal($mol_charset_decode_from(new Uint8Array([0xf0, 0x9f, 0x98, 0x80]), 0, 2), ['😀', 4]);
|
|
4580
|
-
},
|
|
4581
|
-
});
|
|
4582
|
-
})($ || ($ = {}));
|
|
4583
|
-
|
|
4584
4525
|
;
|
|
4585
4526
|
"use strict";
|
|
4586
4527
|
var $;
|
|
@@ -5025,8 +4966,11 @@ var $;
|
|
|
5025
4966
|
},
|
|
5026
4967
|
"vary pack text"($) {
|
|
5027
4968
|
check(['foo'], [text | 3, ...str('foo')]);
|
|
5028
|
-
|
|
5029
|
-
|
|
4969
|
+
check(['абв'], [text | 6, ...str('абв')]);
|
|
4970
|
+
const long_lat = 'abcdefghijklmnopqrst';
|
|
4971
|
+
check([long_lat], [text | L1, 20, ...str(long_lat)]);
|
|
4972
|
+
const long_cyr = 'абвгдеёжзийклмнопрст';
|
|
4973
|
+
check([long_cyr], [text | L1, 40, ...str(long_cyr)]);
|
|
5030
4974
|
},
|
|
5031
4975
|
"vary pack dedup text"($) {
|
|
5032
4976
|
check([["f", "f"]], [list | 2, text | 1, ...str('f'), link | 0]);
|