Files
SnowLuma/.pnpm-store/v11/files/21/805830c616f0ba27f62ab506a70bb532bcc0c933a595a68c71dcd5073c5cfd7f367c63d1530e1a52533b47d0de8b9aade2542dd9e915cb5f3731cb5f7552e3
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

38 lines
1.0 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/utils/encode.ts
/**
* @module
* Encode utility.
*/
const decodeBase64Url = (str) => {
return decodeBase64(str.replace(/_|-/g, (m) => ({
_: "/",
"-": "+"
})[m] ?? m));
};
const encodeBase64Url = (buf) => encodeBase64(buf).replace(/\/|\+/g, (m) => ({
"/": "_",
"+": "-"
})[m] ?? m);
const encodeBase64 = (buf) => {
let binary = "";
const bytes = new Uint8Array(buf);
for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
return btoa(binary);
};
const decodeBase64 = (str) => {
const binary = atob(str);
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
const half = binary.length / 2;
for (let i = 0, j = binary.length - 1; i <= half; i++, j--) {
bytes[i] = binary.charCodeAt(i);
bytes[j] = binary.charCodeAt(j);
}
return bytes;
};
//#endregion
exports.decodeBase64 = decodeBase64;
exports.decodeBase64Url = decodeBase64Url;
exports.encodeBase64 = encodeBase64;
exports.encodeBase64Url = encodeBase64Url;