UNPKG

@yogesh0333/yogiway

Version:

YOGIWAY Format - Ultra-compact, nested-aware data format for LLM prompts. Handles deeply nested JSON efficiently, 10-15% more efficient than TOON.

72 lines (59 loc) 1.87 kB
#!/usr/bin/env node /** * Quick YOGIWAY Compression Tool * Direct, simple compression without VS Code extension * * Usage: * node quick-compress.js <file> * node quick-compress.js <file> | pbcopy (Mac - copy to clipboard) * node quick-compress.js <file> > output.txt */ const fs = require('fs'); const path = require('path'); const { encode } = require('./dist/index'); // Get file path from command line const filePath = process.argv[2]; if (!filePath) { console.error('❌ Usage: node quick-compress.js <file>'); console.error(' Example: node quick-compress.js src/index.ts'); process.exit(1); } if (!fs.existsSync(filePath)) { console.error(`❌ File not found: ${filePath}`); process.exit(1); } try { // Read file const content = fs.readFileSync(filePath, 'utf-8'); const language = path.extname(filePath).slice(1) || 'text'; // Create context const context = { file: { path: path.resolve(filePath), name: path.basename(filePath), language: language, code: content, lines: content.split('\n').length, size: content.length } }; // Encode with optimal settings const compressed = encode(context, { usePathReferences: true, compressPaths: true, adaptiveFlattening: true, lazyPaths: true }); // Output results const originalSize = content.length; const compressedSize = compressed.length; const reduction = ((1 - compressedSize / originalSize) * 100).toFixed(1); // Output compressed data console.log(compressed); // Stats to stderr (so they don't interfere with piping) console.error(`\n✅ Compressed: ${originalSize}${compressedSize} chars (${reduction}% reduction)`); console.error(`📁 File: ${path.basename(filePath)}`); } catch (error) { console.error(`❌ Error: ${error.message}`); process.exit(1); }