This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUtf8 = exports.fromUtf8 = void 0;
const pureJs_1 = require("./pureJs");
const whatwgEncodingApi_1 = require("./whatwgEncodingApi");
const fromUtf8 = (input) => typeof TextEncoder === "function" ? (0, whatwgEncodingApi_1.fromUtf8)(input) : (0, pureJs_1.fromUtf8)(input);
exports.fromUtf8 = fromUtf8;
const toUtf8 = (input) => typeof TextDecoder === "function" ? (0, whatwgEncodingApi_1.toUtf8)(input) : (0, pureJs_1.toUtf8)(input);
exports.toUtf8 = toUtf8;

View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUtf8 = exports.fromUtf8 = void 0;
const fromUtf8 = (input) => {
const bytes = [];
for (let i = 0, len = input.length; i < len; i++) {
const value = input.charCodeAt(i);
if (value < 0x80) {
bytes.push(value);
}
else if (value < 0x800) {
bytes.push((value >> 6) | 0b11000000, (value & 0b111111) | 0b10000000);
}
else if (i + 1 < input.length && (value & 0xfc00) === 0xd800 && (input.charCodeAt(i + 1) & 0xfc00) === 0xdc00) {
const surrogatePair = 0x10000 + ((value & 0b1111111111) << 10) + (input.charCodeAt(++i) & 0b1111111111);
bytes.push((surrogatePair >> 18) | 0b11110000, ((surrogatePair >> 12) & 0b111111) | 0b10000000, ((surrogatePair >> 6) & 0b111111) | 0b10000000, (surrogatePair & 0b111111) | 0b10000000);
}
else {
bytes.push((value >> 12) | 0b11100000, ((value >> 6) & 0b111111) | 0b10000000, (value & 0b111111) | 0b10000000);
}
}
return Uint8Array.from(bytes);
};
exports.fromUtf8 = fromUtf8;
const toUtf8 = (input) => {
let decoded = "";
for (let i = 0, len = input.length; i < len; i++) {
const byte = input[i];
if (byte < 0x80) {
decoded += String.fromCharCode(byte);
}
else if (0b11000000 <= byte && byte < 0b11100000) {
const nextByte = input[++i];
decoded += String.fromCharCode(((byte & 0b11111) << 6) | (nextByte & 0b111111));
}
else if (0b11110000 <= byte && byte < 0b101101101) {
const surrogatePair = [byte, input[++i], input[++i], input[++i]];
const encoded = "%" + surrogatePair.map((byteValue) => byteValue.toString(16)).join("%");
decoded += decodeURIComponent(encoded);
}
else {
decoded += String.fromCharCode(((byte & 0b1111) << 12) | ((input[++i] & 0b111111) << 6) | (input[++i] & 0b111111));
}
}
return decoded;
};
exports.toUtf8 = toUtf8;

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUtf8 = exports.fromUtf8 = void 0;
function fromUtf8(input) {
return new TextEncoder().encode(input);
}
exports.fromUtf8 = fromUtf8;
function toUtf8(input) {
return new TextDecoder("utf-8").decode(input);
}
exports.toUtf8 = toUtf8;