(
input: string | Uint8Array_ | ArrayBuffer,
options: Base64Options = {},
)
| 80 | * ``` |
| 81 | */ |
| 82 | export function encodeBase64( |
| 83 | input: string | Uint8Array_ | ArrayBuffer, |
| 84 | options: Base64Options = {}, |
| 85 | ): string { |
| 86 | options.alphabet ??= "base64"; |
| 87 | if (typeof input === "string") { |
| 88 | input = new TextEncoder().encode(input) as Uint8Array_; |
| 89 | } else if (input instanceof ArrayBuffer) { |
| 90 | input = new Uint8Array(input); |
| 91 | } |
| 92 | let [output, i] = detach( |
| 93 | input as Uint8Array_, |
| 94 | calcSizeBase64((input as Uint8Array_).length), |
| 95 | ); |
| 96 | let o = encode(output, i, 0, alphabet[options.alphabet], padding); |
| 97 | if (options.alphabet === "base64url") { |
| 98 | o = output.indexOf(padding, o - 2); |
| 99 | if (o > 0) output = output.subarray(0, o); |
| 100 | } |
| 101 | return new TextDecoder().decode(output); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * `encodeIntoBase64` takes an input source and encodes it as base64 into the |
nothing calls this directly
no test coverage detected