Encode and decode Base64 strings, with URL-safe and buffer support.
import { base64 } from 'toolmetry';| Function | Parameters | Returns | Description |
|---|---|---|---|
base64.encode | input: string, encoding?: string | string | Encode a string to Base64 |
base64.decode | input: string, encoding?: string | string | Decode a Base64 string |
base64.encodeURL | input: string | string | Encode to URL-safe Base64 |
base64.decodeURL | input: string | string | Decode URL-safe Base64 |
base64.isValid | input: string | boolean | Check if a string is valid Base64 |
base64.encodeBuffer | buffer: ArrayBuffer | Uint8Array | string | Encode buffer to Base64 |
base64.decodeToBuffer | input: string | Uint8Array | Decode Base64 to Uint8Array |
import { base64 } from 'toolmetry';
const encoded = base64.encode('Hello, World!');
// "SGVsbG8sIFdvcmxkIQ=="
const decoded = base64.decode(encoded);
// "Hello, World!"import { base64 } from 'toolmetry';
const urlSafe = base64.encodeURL('Hello+World/Test=');
// "SGVsbG8rV29ybGQvVGVzdA"
const original = base64.decodeURL(urlSafe);
// "Hello+World/Test="import { base64 } from 'toolmetry';
base64.isValid('SGVsbG8='); // true
base64.isValid('not-base64!'); // falseimport { base64 } from 'toolmetry';
const buffer = new Uint8Array([72, 101, 108, 108, 111]);
const encoded = base64.encodeBuffer(buffer);
// "SGVsbG8="
const decoded = base64.decodeToBuffer(encoded);
// Uint8Array [72, 101, 108, 108, 111]