← Runnable Projects

阅读中文版本

Node CSV Pretty-Print CLI

Node CSV Pretty-Print — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-csv-pretty-cli

Entry point: csvpretty.mjs

Install

node csvpretty.mjs data.csv

Run

node csvpretty.mjs sample.csv

Test

node --test csvpretty.test.mjs

Expected output

Reads CSV and prints a column-aligned table with padding.

Dependencies

  • node >=20

Verification evidence

Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Node CSV Pretty-Print CLI is a self-contained typescript command-line program. Reads CSV and prints a column-aligned table with padding.

Install and run

node csvpretty.mjs data.csv
node csvpretty.mjs sample.csv

Project structure

node-csv-pretty-cli/
├── csvpretty.mjs
└── README snippet above

Key source

// csvpretty.mjs
import { readFileSync } from "node:fs";
const rows = readFileSync(process.argv[2],"utf8").trim().split("\n").map(l=>l.split(","));
const w = rows[0].map((_,c)=>Math.max(...rows.map(r=>(r[c]||"").length)));
console.log(rows.map(r=>r.map((v,c)=>v.padEnd(w[c])).join(" ")).join("\n"));

Testing

node --test csvpretty.test.mjs

Expected output

When run with the documented command, the program prints:

id  name \n1   Alice\n2   Bob

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.