mol_dump_lib 0.0.869 → 0.0.870
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 +2 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +33 -4
- package/node.js.map +1 -1
- package/node.mjs +33 -4
- package/node.test.js +50 -8
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +2 -1
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +33 -4
- package/web.js.map +1 -1
- package/web.mjs +33 -4
- package/web.test.js +17 -4
- package/web.test.js.map +1 -1
package/web.mjs
CHANGED
|
@@ -5527,12 +5527,41 @@ var $;
|
|
|
5527
5527
|
"use strict";
|
|
5528
5528
|
var $;
|
|
5529
5529
|
(function ($) {
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5530
|
+
let buf = new Uint8Array(2 ** 12);
|
|
5531
|
+
function $mol_charset_encode(str) {
|
|
5532
|
+
const capacity = str.length * 3;
|
|
5533
|
+
if (buf.byteLength < capacity)
|
|
5534
|
+
buf = new Uint8Array(capacity);
|
|
5535
|
+
return buf.slice(0, $mol_charset_encode_to(str, buf));
|
|
5534
5536
|
}
|
|
5535
5537
|
$.$mol_charset_encode = $mol_charset_encode;
|
|
5538
|
+
function $mol_charset_encode_to(str, buf, from = 0) {
|
|
5539
|
+
let pos = from;
|
|
5540
|
+
for (let i = 0; i < str.length; i++) {
|
|
5541
|
+
let code = str.charCodeAt(i);
|
|
5542
|
+
if (code < 0x80) {
|
|
5543
|
+
buf[pos++] = code;
|
|
5544
|
+
}
|
|
5545
|
+
else if (code < 0x800) {
|
|
5546
|
+
buf[pos++] = 0xc0 | (code >> 6);
|
|
5547
|
+
buf[pos++] = 0x80 | (code & 0x3f);
|
|
5548
|
+
}
|
|
5549
|
+
else if (code < 0xd800 || code >= 0xe000) {
|
|
5550
|
+
buf[pos++] = 0xe0 | (code >> 12);
|
|
5551
|
+
buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
|
|
5552
|
+
buf[pos++] = 0x80 | (code & 0x3f);
|
|
5553
|
+
}
|
|
5554
|
+
else {
|
|
5555
|
+
const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
|
|
5556
|
+
buf[pos++] = 0xf0 | (point >> 18);
|
|
5557
|
+
buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
|
|
5558
|
+
buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
|
|
5559
|
+
buf[pos++] = 0x80 | (point & 0x3f);
|
|
5560
|
+
}
|
|
5561
|
+
}
|
|
5562
|
+
return pos - from;
|
|
5563
|
+
}
|
|
5564
|
+
$.$mol_charset_encode_to = $mol_charset_encode_to;
|
|
5536
5565
|
})($ || ($ = {}));
|
|
5537
5566
|
|
|
5538
5567
|
;
|
package/web.test.js
CHANGED
|
@@ -3148,10 +3148,23 @@ var $;
|
|
|
3148
3148
|
var $;
|
|
3149
3149
|
(function ($) {
|
|
3150
3150
|
$mol_test({
|
|
3151
|
-
'encode
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3151
|
+
'encode empty'() {
|
|
3152
|
+
$mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
|
|
3153
|
+
},
|
|
3154
|
+
'encode 1 octet'() {
|
|
3155
|
+
$mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
|
|
3156
|
+
},
|
|
3157
|
+
'encode 2 octet'() {
|
|
3158
|
+
$mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
|
|
3159
|
+
},
|
|
3160
|
+
'encode 3 octet'() {
|
|
3161
|
+
$mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
|
|
3162
|
+
},
|
|
3163
|
+
'encode 4 octet'() {
|
|
3164
|
+
$mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
|
|
3165
|
+
},
|
|
3166
|
+
'encode surrogate pair'() {
|
|
3167
|
+
$mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
|
|
3155
3168
|
},
|
|
3156
3169
|
});
|
|
3157
3170
|
})($ || ($ = {}));
|