AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Image To Base64 Agent Guide

Agent guide for data URL CSS wrapping and base64 payload byte-length estimation.

AGENTS.md

Guidance for coding agents working on AlexandrAI Tools Image To Base64 in the alexandrai-tools project.

Project overview

This guide covers src/tools/image-to-base64. dataUrlToCss wraps a data URL in a CSS background-image declaration. base64ByteLength finds the comma separator, strips the header, accounts for trailing padding characters, and estimates decoded payload bytes from base64 length. Body.astro reads image files with FileReader.

Primary source files

  • src/tools/image-to-base64/index.ts defines meta, dataUrlToCss, and base64ByteLength.
  • src/tools/image-to-base64/index.test.ts covers CSS wrapping, generic data URL strings, empty and invalid input, known three-byte payloads, and padded two-byte payloads.
  • src/tools/image-to-base64/Body.astro owns file input, FileReader conversion, byte length display, CSS snippet display, and copy behavior.
  • src/tools/image-to-base64/i18n.ts owns localized labels.
  • src/lib/tools.ts registers the tool metadata.

Setup commands

npm install npm test npm run typecheck npm run build npm run dev

Change rules

  • Return a CSS background-image declaration with the data URL in double quotes.
  • Return zero byte length when no comma separator exists.
  • Calculate padding from trailing equals signs.
  • Estimate bytes as floor of length times three divided by four minus padding.
  • Read images locally with FileReader.
  • Keep generated strings client-side.
  • Add tests before supporting raw base64 strings without headers.

Testing

Test CSS wrapping, byte lengths with and without padding, missing header separators, empty strings, large files, copy behavior, preview behavior, and local-only processing.

PR checklist

  • npm test passes for image-to-base64.
  • Pure helper behavior and browser UI behavior are aligned.
  • Generated CSS, Markdown, JSON, or image output remains browser-local.
  • Invalid input, copy behavior, and privacy expectations are covered.