56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var encode_exports = {};
|
|
__export(encode_exports, {
|
|
decodeBase64: () => decodeBase64,
|
|
decodeBase64Url: () => decodeBase64Url,
|
|
encodeBase64: () => encodeBase64,
|
|
encodeBase64Url: () => encodeBase64Url
|
|
});
|
|
module.exports = __toCommonJS(encode_exports);
|
|
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;
|
|
};
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
decodeBase64,
|
|
decodeBase64Url,
|
|
encodeBase64,
|
|
encodeBase64Url
|
|
});
|