@aws-amplify/core
Version:
Core category of aws-amplify
1 lines • 1.92 kB
Source Map (JSON)
{"version":3,"file":"base64Encoder.mjs","sources":["../../../../../src/utils/convert/base64/base64Encoder.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getBtoa } from '../../globalHelpers';\nimport { bytesToString } from './bytesToString';\nexport const base64Encoder = {\n /**\n * Convert input to base64-encoded string\n * @param input - string to convert to base64\n * @param options - encoding options that can optionally produce a base64url string\n * @returns base64-encoded string\n */\n convert(input, options = {\n urlSafe: false,\n skipPadding: false,\n }) {\n const inputStr = typeof input === 'string' ? input : bytesToString(input);\n let encodedStr = getBtoa()(inputStr);\n // urlSafe char replacement and skipPadding options conform to the base64url spec\n // https://datatracker.ietf.org/doc/html/rfc4648#section-5\n if (options.urlSafe) {\n encodedStr = encodedStr.replace(/\\+/g, '-').replace(/\\//g, '_');\n }\n if (options.skipPadding) {\n encodedStr = encodedStr.replace(/=/g, '');\n }\n return encodedStr;\n },\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,aAAa,GAAG;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG;AAC7B,QAAQ,OAAO,EAAE,KAAK;AACtB,QAAQ,WAAW,EAAE,KAAK;AAC1B,KAAK,EAAE;AACP,QAAQ,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAClF,QAAQ,IAAI,UAAU,GAAG,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC7C;AACA;AACA,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE;AAC7B,YAAY,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5E,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,WAAW,EAAE;AACjC,YAAY,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACtD,SAAS;AACT,QAAQ,OAAO,UAAU,CAAC;AAC1B,KAAK;AACL;;;;"}