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.

93 lines 2.75 kB
"use strict"; /** * Converter between YOGIWAY (text) and PATHX (binary) formats */ Object.defineProperty(exports, "__esModule", { value: true }); exports.yogiwayToPathx = yogiwayToPathx; exports.pathxToYogiway = pathxToYogiway; exports.toPathx = toPathx; exports.fromPathx = fromPathx; exports.toYogiway = toYogiway; exports.fromYogiway = fromYogiway; exports.smartEncode = smartEncode; const index_1 = require("./index"); const pathx_1 = require("./pathx"); /** * Convert YOGIWAY text format to PATHX binary format */ function yogiwayToPathx(yogiwayText) { // Decode YOGIWAY to JavaScript object const data = (0, index_1.decode)(yogiwayText); // Encode to PATHX binary return (0, pathx_1.pathxEncode)(data, { optimizePaths: true }); } /** * Convert PATHX binary format to YOGIWAY text format */ function pathxToYogiway(pathxBinary, options) { // Decode PATHX to JavaScript object const data = (0, pathx_1.pathxDecode)(pathxBinary); // Encode to YOGIWAY text return (0, index_1.encode)(data, { useTabs: options?.useTabs !== false, compressPaths: options?.compressPaths !== false, usePathReferences: options?.usePathReferences !== false, }); } /** * Convert JavaScript object to PATHX (for storage/transmission) */ function toPathx(data, options) { return (0, pathx_1.pathxEncode)(data, { compress: options?.compress || false, optimizePaths: options?.optimizePaths !== false, }); } /** * Convert PATHX binary to JavaScript object */ function fromPathx(data) { return (0, pathx_1.pathxDecode)(data); } /** * Convert JavaScript object to YOGIWAY (for LLM prompts) */ function toYogiway(data, options) { return (0, index_1.encode)(data, { useTabs: options?.useTabs !== false, compressPaths: options?.compressPaths !== false, usePathReferences: options?.usePathReferences !== false, }); } /** * Convert YOGIWAY text to JavaScript object */ function fromYogiway(text) { return (0, index_1.decode)(text); } /** * Smart converter: chooses best format based on use case */ function smartEncode(data, useCase = 'llm') { switch (useCase) { case 'llm': // Use YOGIWAY for LLM prompts (text-based, human-readable) return toYogiway(data, { usePathReferences: true }); case 'storage': case 'transmission': // Use PATHX for storage/transmission (binary, optimized) return toPathx(data, { optimizePaths: true }); default: return toYogiway(data); } } exports.default = { yogiwayToPathx, pathxToYogiway, toPathx, fromPathx, toYogiway, fromYogiway, smartEncode, }; //# sourceMappingURL=converter.js.map