Home/Tools/@tpmjs/official-base64-encode

base64EncodeTool

@tpmjs/official-base64-encode

Encode string or buffer to base64 format. Supports utf8 (default), binary, and hex character encodings. Returns the base64 encoded string and the byte length of the original data.

Official
data
v0.1.0
MIT

Interactive Playground

Test @tpmjs/official-base64-encode (base64EncodeTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/official-base64-encode
pnpm add @tpmjs/official-base64-encode
yarn add @tpmjs/official-base64-encode
bun add @tpmjs/official-base64-encode
deno add npm:@tpmjs/official-base64-encode

2. Import the tool

import { base64EncodeTool } from '@tpmjs/official-base64-encode';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { base64EncodeTool } from '@tpmjs/official-base64-encode';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { base64EncodeTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
data
Required
Type: string

The data to encode to base64

encoding
Optional
Type: string

Character encoding of the input data (default: utf8)

Schema extracted: 1/1/2026, 8:18:33 AM

README

@tpmjs/official-base64-encode

Encode string or buffer to base64 format with support for multiple character encodings.

Installation

npm install @tpmjs/official-base64-encode

Usage

import { base64EncodeTool } from '@tpmjs/official-base64-encode';
import { generateText } from 'ai';

const result = await generateText({
  model: yourModel,
  tools: {
    base64Encode: base64EncodeTool,
  },
  prompt: 'Encode "Hello, World!" to base64',
});

Parameters

  • data (string, required): The data to encode to base64
  • encoding (string, optional): Character encoding of the input data
    • Options: 'utf8' (default), 'binary', 'hex'

Returns

{
  base64: string;        // The base64 encoded string
  byteLength: number;    // The byte length of the original data
}

Examples

Encode UTF-8 text (default)

const result = await base64EncodeTool.execute({
  data: 'Hello, World!',
});
// { base64: 'SGVsbG8sIFdvcmxkIQ==', byteLength: 13 }

Encode binary data

const result = await base64EncodeTool.execute({
  data: '\x00\x01\x02\x03',
  encoding: 'binary',
});
// { base64: 'AAECAw==', byteLength: 4 }

Encode hex string

const result = await base64EncodeTool.execute({
  data: 'deadbeef',
  encoding: 'hex',
});
// { base64: '3q2+7w==', byteLength: 4 }

Use Cases

  • Encoding text for data URIs
  • Preparing binary data for transmission
  • Converting hex strings to base64
  • Encoding authentication credentials
  • Creating base64-encoded images or files

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
data
base64
encode
encoding

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai