base64

encode. Namespace

base64

Description:
  • Provides methods for Base64 encoding and decoding. This namespace includes functions to encode and decode strings in Base64 format, which is commonly used for data transmission in web applications. It supports both standard Base64 and URL-safe Base64 encoding.

Methods

(static) decode(base64String) → {string}

Description:
  • Decodes a Base64 string back into a UTF-8 string.
Example
const decoded = base64.decode('SGVsbG8sIFdvcmxkIQ==');
console.log(decoded); // Outputs: Hello, World!
Parameters:
Name Type Description
base64String string The Base64 string to decode.
Returns:
The original UTF-8 string or null if the input is not a string.
Type
string

(static) decodeUrl(input) → {string}

Description:
  • Decodes a Base64Url encoded string. This reverses the URL-safe encoding by replacing '-' with '+', '_' with '/', and adding padding if necessary. It is useful for decoding data that was encoded for use in URLs or HTTP headers.
Example
const decodedUrl = base64.decodeUrl('SGVsbG8sIFdvcmxkIQ');
console.log(decodedUrl); // Outputs: Hello, World!
Parameters:
Name Type Description
input string The Base64Url string.
Returns:
The decoded string.
Type
string

(static) encode(inputString) → {string}

Description:
  • Encodes a UTF-8 string into a Base64 string.
Example
const encoded = base64.encode('Hello, World!');
console.log(encoded); // Outputs: SGVsbG8sIFdvcmxkIQ==
Parameters:
Name Type Description
inputString string The string to encode.
Returns:
The Base64 encoded string or null if the input is not a string.
Type
string

(static) encodeUrl(input) → {string}

Description:
  • Encodes a string using the URL-safe Base64 variant. This replaces '+' with '-', '/' with '_', and removes padding ('='). It is useful for encoding data that will be included in URLs or HTTP headers.
Example
const encodedUrl = base64.encodeUrl('Hello, World!');
console.log(encodedUrl); // Outputs: SGVsbG8sIFdvcmxkIQ==
Parameters:
Name Type Description
input string The string or buffer to encode.
Returns:
The Base64Url encoded string.
Type
string