How juanjodiaz/json2csv works
Main Components
• Core Parsing Engine:
– The “Plainjs” package provides the synchronous parser and stream parser in pure JavaScript. This is effectively the base engine used by other packages.
• Wrappers/Interfaces for Different Environments:
– The “Node” package uses the core engine to build a Node.js Transform Stream and an asynchronous parser API.
– The “WHATWG” package wraps around the core streaming parser to leverage the WHATWG Transform Stream, aimed at browser (web streams) usage.
– The “CLI” package exposes these functionalities as a command line utility.
• Support Libraries:
– The “Transforms” package includes built-in data transformation functions (like flatten and unwind) to preprocess the JSON before conversion.
– The “Formatters” package provides a set of custom CSV cell formatting functions (e.g., for numbers, strings, objects, special excel formatting, etc.).
• Additional Tools:
– Support packages such as “test-helpers” and “test-performance” help with testing, benchmarking, and validation, though they are auxiliary and do not contribute directly to the runtime architecture.
Technical Stack & Design Patterns
• Modularity: The project is split into multiple packages each responsible for a specific part of the JSON-to-CSV conversion process.
• Use labels to clearly differentiate synchronous and asynchronous processes:
• Shared architectural patterns:
– Dependency Inversion is evident since the core library is abstracted from its environment-specific wrappers.
– The strategy of using pluggable “Transforms” and “Formatters” represents both modular design and separation of concerns.