encodeStd (src/index.ts)

voleeo-api · plugins/base64/src/index.ts · typescript · MIT
auth

Standard and URL-safe Base64 encode/decode functions with UTF-8 support, exposed as template functions.

// Source: https://github.com/voleeo/voleeo-api | License: MIT | Copyright 2026 Voleeo
// Provided via justclaw.it.com; keep this notice with the code.
import type {
  TemplateFunctionContribution,
  VoleeoPlugin,
} from "@voleeo/plugin-api"

/**
 * UTF-8 → standard base64 (RFC 4648 §4).
 * `btoa` only accepts Latin-1 — go through `TextEncoder` so multi-byte
 * sequences (`é`, `北京`, emoji) survive the trip.
 */
function encodeStd(text: string): string {
  const bytes = new TextEncoder().encode(text)
  let bin = ""
  for (const b of bytes) bin += String.fromCharCode(b)
  return btoa(bin)
}

/** Standard base64 → UTF-8 string. `atob` returns a Latin-1 string; decode
 *  the byte view through `TextDecoder` for multi-byte fidelity. */
function decodeStd(b64: string): string {
  const bin = ato

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key