2 return 0x80 | (n & 0x3f);
5 export function encode(str) {
6 const arr = str.split("").map(x => x.charCodeAt(0));
10 function _encode(arr) {
11 if (arr.length === 0) {
15 const [n, ...ns] = arr;
18 throw new Error("utf8");
22 return [n, ..._encode(ns)];
26 return [0xc0 | (n >>> 6), con(n), ..._encode(ns)];
30 return [0xe0 | (n >>> 12), con(n >>> 6), con(n), ..._encode(ns)];
43 throw new Error("utf8");