Release extension 3.2.0 with ZWUS-7 and large text support

This commit is contained in:
2026-09-16 16:50:56 -07:00
parent 2150671b97
commit d840ffd5f9
22 changed files with 3654 additions and 64 deletions

34
chunked.js Normal file
View File

@@ -0,0 +1,34 @@
import zwus from 'zwus';
const SIZE = 65536;
function encode(values, base, method) {
const parts = [];
for (let start = 0; start < values.length;) {
let end = Math.min(start + SIZE, values.length);
if (typeof values === 'string' && end < values.length &&
values.charCodeAt(end - 1) >= 0xD800 && values.charCodeAt(end - 1) <= 0xDBFF) end--;
parts.push(zwus[method](values.slice(start, end), base));
start = end;
}
return parts.join(zwus[base].unifier);
}
function decode(text, base, method) {
const parts = [], sep = zwus[base].unifier;
for (let start = 0; start < text.length;) {
let end = Math.min(start + SIZE, text.length);
if (end < text.length) {
const cut = text.lastIndexOf(sep, end - 1);
end = cut >= start ? cut + 1 : (text.indexOf(sep, end) + 1 || text.length);
}
parts.push(zwus[method](text.slice(start, end), base));
start = end;
}
return method === 'decodeToString' ? parts.join('') : parts.flat();
}
export const encodeString = (text, base) => encode(text, base, 'encodeString');
export const encodeNumberArray = (numbers, base) => encode(numbers, base, 'encodeNumberArray');
export const decodeToString = (text, base) => decode(text, base, 'decodeToString');
export const decodeToNumberArray = (text, base) => decode(text, base, 'decodeToNumberArray');