TypeScript provides built-in support for base64 encoding/decoding through the btoa and atob functions in the global scope.
The string encodes to slightly different values with the standard and URL base64 encoders (trailing + vs -) but they both decode to the original string as desired.
To run this TypeScript code, you would typically compile it to JavaScript and then run it with Node.js. Here’s an example of how you might do that:
Note that TypeScript doesn’t have built-in URL-safe base64 encoding, so we’ve implemented simple functions to convert between standard and URL-safe base64. In a real-world scenario, you might want to use a library that provides more robust implementations of these functions.