Skip to content

@technobuddha > library > Binary > Encoding

Function: encodeBase64Url() ​

Creates a encoded ASCII string from a BinaryObject or string using Base64Url.

You can use this method to encode data which may otherwise cause communication problems, transmit it, then use the decodeBase64Url method to decode the data again. For example, you can encode control characters.

Call Signature ​

ts
function encodeBase64Url(chars: string, encoding: TextEncoding): string;

Defined in: encode-base64-url.ts:19

Convert a string to binary using encodeText with the supplied encoding, and then encode it to Base64Url.

Parameters ​

ParameterTypeDescription
charsstringThe string to encode
encodingTextEncodingThe encoding of the input string

Returns ​

string

An ASCII string containing the Base64Url representation

Example ​

typescript
encodeBase64Url('Hello, world!', 'utf8'); // "SGVsbG8sIHdvcmxkIQ"

Call Signature ​

ts
function encodeBase64Url(binary: BinaryObject): string;

Defined in: src/encode-base64-url.ts:29

Encode a BinaryObject to a Base64Url string.

Parameters ​

ParameterTypeDescription
binaryBinaryObjectThe Binary object to encode

Returns ​

string

An ASCII string containing the Base64Url representation

Example ​

typescript
encodeBase64Url(new Uint8Array([1, 2, 3])); // "AQID"