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,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maxLetterValue = exports.bitsPerByte = exports.bitsPerLetter = exports.alphabetByValue = exports.alphabetByEncoding = void 0;
const alphabetByEncoding = {};
exports.alphabetByEncoding = alphabetByEncoding;
const alphabetByValue = new Array(64);
exports.alphabetByValue = alphabetByValue;
for (let i = 0, start = "A".charCodeAt(0), limit = "Z".charCodeAt(0); i + start <= limit; i++) {
const char = String.fromCharCode(i + start);
alphabetByEncoding[char] = i;
alphabetByValue[i] = char;
}
for (let i = 0, start = "a".charCodeAt(0), limit = "z".charCodeAt(0); i + start <= limit; i++) {
const char = String.fromCharCode(i + start);
const index = i + 26;
alphabetByEncoding[char] = index;
alphabetByValue[index] = char;
}
for (let i = 0; i < 10; i++) {
alphabetByEncoding[i.toString(10)] = i + 52;
const char = i.toString(10);
const index = i + 52;
alphabetByEncoding[char] = index;
alphabetByValue[index] = char;
}
alphabetByEncoding["+"] = 62;
alphabetByValue[62] = "+";
alphabetByEncoding["/"] = 63;
alphabetByValue[63] = "/";
const bitsPerLetter = 6;
exports.bitsPerLetter = bitsPerLetter;
const bitsPerByte = 8;
exports.bitsPerByte = bitsPerByte;
const maxLetterValue = 0b111111;
exports.maxLetterValue = maxLetterValue;

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromBase64 = void 0;
const constants_browser_1 = require("./constants.browser");
const fromBase64 = (input) => {
let totalByteLength = (input.length / 4) * 3;
if (input.slice(-2) === "==") {
totalByteLength -= 2;
}
else if (input.slice(-1) === "=") {
totalByteLength--;
}
const out = new ArrayBuffer(totalByteLength);
const dataView = new DataView(out);
for (let i = 0; i < input.length; i += 4) {
let bits = 0;
let bitLength = 0;
for (let j = i, limit = i + 3; j <= limit; j++) {
if (input[j] !== "=") {
if (!(input[j] in constants_browser_1.alphabetByEncoding)) {
throw new TypeError(`Invalid character ${input[j]} in base64 string.`);
}
bits |= constants_browser_1.alphabetByEncoding[input[j]] << ((limit - j) * constants_browser_1.bitsPerLetter);
bitLength += constants_browser_1.bitsPerLetter;
}
else {
bits >>= constants_browser_1.bitsPerLetter;
}
}
const chunkOffset = (i / 4) * 3;
bits >>= bitLength % constants_browser_1.bitsPerByte;
const byteLength = Math.floor(bitLength / constants_browser_1.bitsPerByte);
for (let k = 0; k < byteLength; k++) {
const offset = (byteLength - k - 1) * constants_browser_1.bitsPerByte;
dataView.setUint8(chunkOffset + k, (bits & (255 << offset)) >> offset);
}
}
return new Uint8Array(out);
};
exports.fromBase64 = fromBase64;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromBase64 = void 0;
const util_buffer_from_1 = require("@smithy/util-buffer-from");
const BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
const fromBase64 = (input) => {
if ((input.length * 3) % 4 !== 0) {
throw new TypeError(`Incorrect padding on base64 string.`);
}
if (!BASE64_REGEX.exec(input)) {
throw new TypeError(`Invalid base64 string.`);
}
const buffer = (0, util_buffer_from_1.fromString)(input, "base64");
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
};
exports.fromBase64 = fromBase64;

View File

@@ -0,0 +1,27 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
module.exports = __toCommonJS(src_exports);
__reExport(src_exports, require("././fromBase64"), module.exports);
__reExport(src_exports, require("././toBase64"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fromBase64,
toBase64
});

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toBase64 = void 0;
const util_utf8_1 = require("@smithy/util-utf8");
const constants_browser_1 = require("./constants.browser");
function toBase64(_input) {
let input;
if (typeof _input === "string") {
input = (0, util_utf8_1.fromUtf8)(_input);
}
else {
input = _input;
}
const isArrayLike = typeof input === "object" && typeof input.length === "number";
const isUint8Array = typeof input === "object" &&
typeof input.byteOffset === "number" &&
typeof input.byteLength === "number";
if (!isArrayLike && !isUint8Array) {
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
}
let str = "";
for (let i = 0; i < input.length; i += 3) {
let bits = 0;
let bitLength = 0;
for (let j = i, limit = Math.min(i + 3, input.length); j < limit; j++) {
bits |= input[j] << ((limit - j - 1) * constants_browser_1.bitsPerByte);
bitLength += constants_browser_1.bitsPerByte;
}
const bitClusterCount = Math.ceil(bitLength / constants_browser_1.bitsPerLetter);
bits <<= bitClusterCount * constants_browser_1.bitsPerLetter - bitLength;
for (let k = 1; k <= bitClusterCount; k++) {
const offset = (bitClusterCount - k) * constants_browser_1.bitsPerLetter;
str += constants_browser_1.alphabetByValue[(bits & (constants_browser_1.maxLetterValue << offset)) >> offset];
}
str += "==".slice(0, 4 - bitClusterCount);
}
return str;
}
exports.toBase64 = toBase64;

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toBase64 = void 0;
const util_buffer_from_1 = require("@smithy/util-buffer-from");
const util_utf8_1 = require("@smithy/util-utf8");
const toBase64 = (_input) => {
let input;
if (typeof _input === "string") {
input = (0, util_utf8_1.fromUtf8)(_input);
}
else {
input = _input;
}
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
}
return (0, util_buffer_from_1.fromArrayBuffer)(input.buffer, input.byteOffset, input.byteLength).toString("base64");
};
exports.toBase64 = toBase64;