CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-snazzy

Format JavaScript Standard Style as Stylish (i.e. snazzy) output

94

1.18x
Overview
Eval results
Files

task.mdevals/scenario-3/

CSV to JSON Stream Transformer

Build a command-line tool that transforms CSV data into JSON format using Node.js streams. The tool should read CSV data from stdin, convert it to JSON, and output the result to stdout.

Requirements

The tool should:

  1. Accept CSV data via stdin (pipe support)
  2. Parse the CSV data where:
    • The first row contains column headers
    • Subsequent rows contain data values
    • Fields are comma-separated
    • Whitespace around commas should be trimmed
  3. Convert each data row to a JSON object using headers as keys
  4. Output a JSON array containing all row objects
  5. Handle the complete input before producing output (buffer all data, then process)
  6. Work as a standard Unix pipeline tool

Input Format

name, age, city
Alice, 30, Seattle
Bob, 25, Portland

Output Format

[
  {"name": "Alice", "age": "30", "city": "Seattle"},
  {"name": "Bob", "age": "25", "city": "Portland"}
]

Test Cases

  • When given CSV with headers "id,name" and one data row "1,Test", outputs [{"id":"1","name":"Test"}] @test
  • When given empty input (no data), outputs an empty array [] @test
  • When given CSV with headers "x,y,z" and two rows "a,b,c" and "d,e,f", outputs [{"x":"a","y":"b","z":"c"},{"x":"d","y":"e","z":"f"}] @test

Implementation Notes

@generates

Create a CLI script that can be executed with node src/csv-to-json-stream.js or piped to like echo "a,b\n1,2" | node src/csv-to-json-stream.js.

API

/**
 * A Transform stream that converts CSV input to JSON output.
 * Buffers all input chunks, then processes the complete CSV data
 * and outputs a JSON array of objects.
 */
class CsvToJsonStream {
  constructor(options);
}

module.exports = CsvToJsonStream;

Dependencies { .dependencies }

snazzy { .dependency }

Provides stream transformation capabilities using Node.js Transform streams. Use its implementation pattern as reference for building custom stream transformers.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-snazzy

tile.json