Format & Structure Detection
Unified detection: use detectFormat() for quick format sniffing ordetectStructure() to extract fields, delimiters and XML record elements.
Quick examples
import { detectFormat, detectStructure, ConvertBuddy } from 'convert-buddy-js';
// Detect format from any input
const format = await detectFormat(input);
// Inspect structure for parser hints
const structure = await detectStructure(input);
// Use detection result when streaming
const controller = new ConvertBuddy().stream(input, {
inputFormat: format,
outputFormat: 'ndjson',
onRecords: (ctrl, records) => { console.log(records); }
});
await controller.done;When to use detection
- Unknown uploads or third-party feeds
- Adaptive pipelines that tune CSV/XML options
- Preflight checks before long-running conversions
Best practices
- Default
inputFormatis auto-detect; only call detection when you need metadata - Use
maxBytesto limit sample size (default ~256KB) - Always handle
"unknown"results with a fallback