Skip to content

base64Decode

Decodes a Base64 or Base64URL string to a Uint8Array.

Syntax

typescript
base64Decode(input: string, urlSafe?: boolean): Uint8Array

Parameters

NameTypeDescription
inputstringThe Base64 or Base64URL encoded string to decode
urlSafeboolean(Optional) If true, treats the input as Base64URL. Default is false

Returns

TypeDescription
Uint8ArrayThe decoded byte array

Example

typescript
const data = base64Decode("SGVsbG8gV29ybGQh");
console.log(new TextDecoder().decode(data)); // "Hello World!"

Notes

  • Throws an error if the input is not a valid Base64/Base64URL string.

References

Released under the MIT License.