lemukarram / toon
A compact, token-efficient data format for AI prompts, developed by Tech With Muk.
Requires
- php: ^8.1
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2026-03-10 12:27:28 UTC
README
A lightweight, token-efficient data format specifically designed for optimizing AI prompts in Laravel applications. Developed by Mukarram Hussain of Tech with muk.
When sending data to LLMs (like ChatGPT, Claude, or Gemini), standard JSON uses too many tokens due to repeated keys and braces. This package converts your PHP arrays into a highly compact, human-readable "Toon" notation, saving you money and context window space.
Features
- 🚀
jsonToToon: Convert PHP Arrays or JSON to compact notation. - 🔢
countTokens: Estimate the token usage of your strings. - 📉 Smart Compression: Automatically converts lists of objects (like Eloquent collections) into a clean, CSV-style table format to save maximum tokens.
Installation
You can install the package via composer:
composer require lemukarram/toon
The package will automatically register its service provider and facade.
Usage
1. Compressing Data for AI Prompts
Use the Toon facade to convert your data before sending it to an AI API.
use LeMukarram\Toon\Facades\Toon; $data = [ 'user' => 'Mukarram', 'skills' => ['Laravel', 'PHP', 'AI', 'CodeIgniter', 'Shopify'], 'projects' => [ ['name' => 'AI Influencer', 'status' => 'Active'], ['name' => 'Laravel Package', 'status' => 'Done'], ] ]; $promptContext = Toon::jsonToToon($data); /* * The output ($promptContext) will be: * * user: Mukarram * skills: * 0: Laravel * 1: PHP * 2: AI * 3: CodeIgniter * 4: Shopify * projects: * @[2](name,status): * "AI Influencer",Active * "Laravel Package",Done */
2. Estimating Token Usage
Check how many tokens you are saving.
$jsonTokens = Toon::countTokens(json_encode($data)); $toonTokens = Toon::countTokens($promptContext); echo "JSON Tokens: $jsonTokens"; // e.g., ~70 echo "Toon Tokens: $toonTokens"; // e.g., ~45
Credits
- Mukarram Hussain (Tech with muk)
License
The MIT License (MIT). Please see License File for more information.