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

base64EncodeTool

@tpmjs/official-base64-encode

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

Official
data
v0.1.1
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);

Signature

(data: string, encoding?: string) => Promise<unknown>

Tags

base64
base64encode
buffer
character
data
encode
encoding
encodings
format
multiple
official
string
support
tpmjs

Parameters

Available configuration options

Auto-extracted
data
Required
Type: string

The data to encode

encoding
Optional
Type: string

Character encoding (utf8, binary, hex)

Schema extracted: 3/1/2026, 4:28:02 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

21

GitHub Stars

0

Quality Score

76%

Bundle Size

NPM Keywords

tpmjs
data
base64
encode
encoding

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai
base64EncodeTool | TPMJS | TPMJS