Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including csv2md with all npm packages installed. Try it out:

var csv2md = require("csv2md")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

csv2md v0.1.2

csv2md transforms csv data to markdown table data

Transforms csv to markdown table

Build Status

Install with:

  $ npm install -g csv2md

Small tool to convert (larger) csv to markdown tables. Processes stdin or csv file.

Usage

  $ csv2md data.csv > data.md

Piping data is possible (and recommend for larger files):

  $ cat data.csv | csv2md

  | max_i | min_i | max_f | min_f |
  |---|---|---|---|
  | -122.1430195 | -122.1430195 | -122.415278 | 37.778643 |
  | -122.1430195 | -122.1430195 | -122.40815 | 37.785034 |
  | -122.4194155 | -122.4194155 | -122.4330827 | 37.7851673 |
  …
  $ cat data.csv | csv2md > data.md

The pretty option will pad cells to uniform width, but will disable stream processing.

  $ csv2md --pretty data.csv > data.md

  | max_i        | min_i        | max_f        | min_f      |
  |--------------|--------------|--------------|------------|
  | -122.1430195 | -122.1430195 | -122.415278  | 37.778643  |
  | -122.1430195 | -122.1430195 | -122.40815   | 37.785034  |
  | -122.4194155 | -122.4194155 | -122.4330827 | 37.7851673 |
  …

Options

Use -h for more command options:

  $ csv2md -h

Using csv2md synchronously via require

For example:

  let csv2md = require('csv2md').csv2md;

  let csvString = `
  a,b,c_1,c_2
  -122.1430195,124.3,true,false
  null, a ,a very long string,~
  a,b,c_1,c_2
  `.trim()

  let markdown = csv2md(csvString, {
    pretty: true
  });

  console.log(markdown);

will output:

| a            | b     | c_1                | c_2   |
|--------------|-------|--------------------|-------|
| -122.1430195 | 124.3 | true               | false |
| null         | a     | a very long string | ~     |
| a            | b     | c_1                | c_2   |

Tests

Ensure that you have mocha installed npm install -g mocha, then run:

  $ npm run test

Contributors

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free