{
  "version": 3,
  "sources": ["../../src/utils/decoders/base64Utils.ts"],
  "sourcesContent": ["/**\n * @description Checks if a string is base64 encoded\n * The detection difficulty stands in the format of an encoded string that initially had non-ASCII characters\n *\n * Usually, when decoding a base64 string, if the result has non-ASCII characters,\n * it means that the string was encoded, however, this is not always the case\n *\n * @example If we encode a string with non-ASCII characters like \"\uD83D\uDC4Bwxyz{|}~\uFFFD\uFFFD\uFFFD\" to base64\n * the decoded result will also contain non-ASCII characters, but the strings is valid\n * For the scenarios above, the Buffer.from() conversion is not equal to the atob() conversion\n * and, the encoded string format is also different from a regular base64 string (e.g. \"GamRHHZiaUR3bjVtQQ==\")\n *\n * Solution:\n * - if any conversion fails (atob(), btoa() or Buffer.from()), it is definitely not an encoded string\n * - if the string is equal\n *\n * @see The tests for this function are in src/utils/decoders/tests/base64Utils.test.ts\n * @param str\n */\nexport function isStringBase64(str: string) {\n  if (!str) {\n    return false;\n  }\n\n  try {\n    // Try to decode the string and encode it back using base64 functions\n    const atobDecoded = atob(str);\n    const btoaEncoded = btoa(atobDecoded);\n    const bufferFromDecoded = Buffer.from(str, 'base64').toString('utf8');\n    const bufferFromEncoded = Buffer.from(bufferFromDecoded, 'utf8').toString(\n      'base64'\n    );\n\n    // If the result is equal to the initial string\n    const isBtoaEqual = str === btoaEncoded || btoaEncoded.startsWith(str);\n    const isBufferFromBase64Equal =\n      str === bufferFromEncoded || bufferFromEncoded.startsWith(str);\n    const isEqualToInitialString = isBtoaEqual && isBufferFromBase64Equal;\n\n    if (isEqualToInitialString) {\n      // it is a regular base64 string\n      return true;\n    }\n  } catch (_) {\n    return false;\n  }\n\n  return false;\n}\n\nexport function encodeToBase64(string: string) {\n  try {\n    return Buffer.from(string, 'utf8').toString('base64');\n  } catch (_) {\n    return '';\n  }\n}\n\nexport function decodeBase64(str: string) {\n  if (!isStringBase64(str)) {\n    return str;\n  }\n\n  try {\n    return Buffer.from(str, 'base64').toString('utf8');\n  } catch (_) {\n    return str;\n  }\n}\n"],
  "mappings": "AAmBO,SAASA,EAAeC,EAAa,CAC1C,GAAI,CAACA,EACH,MAAO,GAGT,GAAI,CAEF,IAAMC,EAAc,KAAKD,CAAG,EACtBE,EAAc,KAAKD,CAAW,EAC9BE,EAAoB,OAAO,KAAKH,EAAK,QAAQ,EAAE,SAAS,MAAM,EAC9DI,EAAoB,OAAO,KAAKD,EAAmB,MAAM,EAAE,SAC/D,QACF,EAGME,EAAcL,IAAQE,GAAeA,EAAY,WAAWF,CAAG,EAC/DM,EACJN,IAAQI,GAAqBA,EAAkB,WAAWJ,CAAG,EAG/D,GAF+BK,GAAeC,EAI5C,MAAO,EAEX,MAAY,CACV,MAAO,EACT,CAEA,MAAO,EACT,CAEO,SAASC,EAAeC,EAAgB,CAC7C,GAAI,CACF,OAAO,OAAO,KAAKA,EAAQ,MAAM,EAAE,SAAS,QAAQ,CACtD,MAAY,CACV,MAAO,EACT,CACF,CAEO,SAASC,EAAaT,EAAa,CACxC,GAAI,CAACD,EAAeC,CAAG,EACrB,OAAOA,EAGT,GAAI,CACF,OAAO,OAAO,KAAKA,EAAK,QAAQ,EAAE,SAAS,MAAM,CACnD,MAAY,CACV,OAAOA,CACT,CACF",
  "names": ["isStringBase64", "str", "atobDecoded", "btoaEncoded", "bufferFromDecoded", "bufferFromEncoded", "isBtoaEqual", "isBufferFromBase64Equal", "encodeToBase64", "string", "decodeBase64"]
}
