Base64Url Helpers
Base64Url helpers provide functions to encode and decode base64url strings, a URL-safe variant of base64 encoding used in web tokens, data serialization, and APIs.
Basic Usage
import { function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefinedDecodes a base64url string to Uint8Array
Returns undefined if the input is invaliddecodeBase64url, function encodeBase64url(data: Uint8Array): stringEncodes a Uint8Array to base64url format
Base64url is URL-safe and doesn't use paddingencodeBase64url } from '@orpc/server/helpers'
const const originalText: "Hello World"originalText = 'Hello World'
const const textBytes: Uint8Array<ArrayBuffer>textBytes = new var TextEncoder: new () => TextEncoderThe **`TextEncoder`** interface enables you to encode a JavaScript string using UTF-8.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoder)TextEncoder().TextEncoder.encode(input?: string): Uint8Array<ArrayBuffer>The **`TextEncoder.encode()`** method takes a string as input, and returns a Uint8Array containing the string encoded using UTF-8.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoder/encode)encode(const originalText: "Hello World"originalText)
const const encodedData: stringencodedData = function encodeBase64url(data: Uint8Array): stringEncodes a Uint8Array to base64url format
Base64url is URL-safe and doesn't use paddingencodeBase64url(const textBytes: Uint8Array<ArrayBuffer>textBytes)
const const decodedBytes: Uint8Array<ArrayBuffer> | undefineddecodedBytes = function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefinedDecodes a base64url string to Uint8Array
Returns undefined if the input is invaliddecodeBase64url(const encodedData: stringencodedData)
const const decodedText: stringdecodedText = new var TextDecoder: new (label?: string, options?: TextDecoderOptions) => TextDecoderThe **`TextDecoder`** interface represents a decoder for a specific text encoding, such as UTF-8, ISO-8859-2, or GBK. A decoder takes an array of bytes as input and returns a JavaScript string.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/TextDecoder)TextDecoder().TextDecoder.decode(input?: AllowSharedBufferSource, options?: TextDecodeOptions): stringThe **`TextDecoder.decode()`** method returns a string containing text decoded from the buffer passed as a parameter.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/TextDecoder/decode)decode(const decodedBytes: Uint8Array<ArrayBuffer> | undefineddecodedBytes) // 'Hello World'