const _fromCC = String.fromCharCode.bind(String);
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, "");
const _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 === "+" ? "-" : "_");
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 === "-" ? "+" : "/"));
const _TD = new TextDecoder();
const _TE = new TextEncoder();
const _fromUint8Array = (u8a) => {
  const maxargs = 4096;
  const strs = [];
  for (let i = 0, l = u8a.length; i < l; i += maxargs) {
    strs.push(_fromCC(...Array.from(u8a.subarray(i, i + maxargs))));
  }
  return btoa(strs.join(""));
};
const _toUint8Array = (a) => {
  return Uint8Array.from(
    atob(a).split("").map((c) => c.charCodeAt(0))
  );
};
const stringToBase64 = (src, urlsafe = false) => {
  const encoded = _fromUint8Array(_TE.encode(src));
  return urlsafe ? _mkUriSafe(encoded) : encoded;
};
const base64ToString = (src) => {
  return _TD.decode(_toUint8Array(_unURI(src)));
};
const stringToBase64URI = (src) => {
  return stringToBase64(src, true);
};
const isBase64 = (src) => {
  if (typeof src !== "string") return false;
  const s = src.replace(/\s+/g, "").replace(/={0,2}$/, "");
  return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
};
const uint8ArrayToBase64 = (u8a, urlsafe = false) => {
  const encoded = _fromUint8Array(u8a);
  return urlsafe ? _mkUriSafe(encoded) : encoded;
};
const base64ToUint8Array = (src) => {
  return _toUint8Array(_unURI(src));
};

export { base64ToString, base64ToUint8Array, isBase64, stringToBase64, stringToBase64URI, uint8ArrayToBase64 };
//# sourceMappingURL=base64.mjs.map
