All files decode-base64.ts

100% Statements 4/4
100% Branches 3/3
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45  1x                                                                               1x 21x 21x  
import { type TextEncoding } from './@types/text-encoding.ts';
import { base64Config, decode } from './base64.ts';
 
// cspell:ignore Hdvcmxk
/**
 * Decode a [Base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64) encoded string and
 * output in binary format.
 * @param input - A string containing the Base64 encoded data to decode.
 * @returns An `Uint8Array` containing the decoded data.
 * @example
 * ```typescript
 * decodeBase64('SGVsbG8sIHdvcmxkIQ==');
 * // Uint8Array([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33])
 * ```
 */
export function decodeBase64(input: string): Uint8Array;
/**
 * Decode a [Base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64) encoded string as a
 * string with the specified text encoding.
 * @param input - A string containing the Base64 encoded data to decode.
 * @param encoding - The text encoding to use for the decoded string.
 * @returns An `string` containing the decoded data.
 * @example
 * ```typescript
 * decodeBase64('SGVsbG8sIHdvcmxkIQ==', 'utf-8');
 * // "Hello, world!"
 * ```
 */
export function decodeBase64(input: string, encoding: TextEncoding): string;
/**
 * Decodes a string of data which has been encoded using
 * [Base64](https://developer.mozilla.org/en-US/docs/Glossary/Base64) encoding.
 *
 * You can use the **decodeBase64** method to encode and transmit data which may otherwise cause
 * communication problems, then transmit it and use the {@link encodeBase64} method to decode the data again.
 * For example, you can encode, transmit, and decode control characters.
 * @remarks Whitespace withing the Base64 encoded string is ignored.
 * @throws `TypeError` If the input string is not correctly encoded.
 * @group Binary
 * @category Encoding
 */
export function decodeBase64(input: string, encoding?: TextEncoding): Uint8Array | string {
  return encoding ? decode(base64Config, input, encoding) : decode(base64Config, input);
}