# csv-to-markdown-table

> JavaScript/Node.js Csv to Markdown Table Converter

Latest version **2.0.0** (published 2026-09-10) · MIT license · 47.0K weekly downloads

## Install

```sh
npm install csv-to-markdown-table
pnpm add csv-to-markdown-table
yarn add csv-to-markdown-table
bun add csv-to-markdown-table
```

Provides the command `csv-to-markdown-table`.

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Negative: declining downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-09-10 |
| First published | 2017-04-10 |
| Weekly downloads | 47.0K |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 135.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 300 |
| Author | Jesse G. Donat |
| Maintainers | donatj |
| Keywords | csv, markdown, github |

## Links

- npm: https://www.npmjs.com/package/csv-to-markdown-table
- Repository: https://github.com/donatj/CsvToMarkdownTable
- Homepage: https://donatstudios.com/CsvToMarkdownTable
- Issues: https://github.com/donatj/CsvToMarkdownTable/issues
- npm.io page: https://npm.io/package/csv-to-markdown-table

## Dependencies (1)

- [csv-walker](https://npm.io/package/csv-walker.md) ^0.2.1

## Alternatives

- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads
- [@1selfworld/adchain-sdk-react-native](https://npm.io/package/@1selfworld/adchain-sdk-react-native.md) — 80 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-09-10
- 1.6.3 — 2025-10-31
- 1.6.2 — 2025-07-29
- 1.6.1 — 2025-07-29
- 1.6.0 — 2025-07-29
- 1.5.0 — 2025-03-25
- 1.4.1 — 2023-12-01
- 1.4.0 — 2023-12-01
- 1.3.1 — 2023-07-10
- 1.3.0 — 2022-11-30
- 1.2.0 — 2022-10-10
- 1.1.0 — 2019-12-12
- 1.0.1 — 2019-07-08
- 1.0.0 — 2019-07-08
- 0.5.0 — 2018-12-26
- … 4 more at https://npm.io/package/csv-to-markdown-table/versions

## README

# CSV To Markdown Table

[![npm version](https://badge.fury.io/js/csv-to-markdown-table.svg)](https://badge.fury.io/js/csv-to-markdown-table)
![npm](https://img.shields.io/npm/dt/csv-to-markdown-table.svg?color=blue)
[![Coverage Status](https://coveralls.io/repos/github/donatj/CsvToMarkdownTable/badge.svg?branch=master)](https://coveralls.io/github/donatj/CsvToMarkdownTable?branch=master)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/donatj/csvtomarkdowntable/master/LICENSE.md)

Simple JavaScript CSV to Markdown Table Converter

You can see it in action and play with the [Live Example](https://donatstudios.com/CsvToMarkdownTable).

Uses [csv-walker](https://www.npmjs.com/package/csv-walker) for CSV parsing.
Works in Node.js (>=20) as well as in the browser.

## Install

```bash
npm install csv-to-markdown-table
```

## Usage

### CLI

This package also includes a CLI tool. You can install it globally with:

```bash
npm install -g csv-to-markdown-table
```

Then you can use it like so:

```bash
$ csv-to-markdown-table --help
Usage: csv-to-markdown-table [options]
// … help output

$ csv-to-markdown-table --delim ',' --headers < example.csv
| cats | dogs | fish | 
|------|------|------|
| 1    | 2    | 3    | 
| 4    | 5    | 6    |
$ csv-to-markdown-table
Reading from stdin... (press Ctrl+D at the start of a line to finish)
CSV Delimiter: \t (tab) Headers: false
[interactive input]
```

### Browser via CDN (UMD)

```html
<script src="https://unpkg.com/csv-to-markdown-table"></script>
<script>
  console.log(
    csvToMarkdown("Name,Role,Location\nAda Lovelace,Mathematician,London\nGrace Hopper,Computer scientist,New York", ",", true)
  );
</script>
```

### Node.js with CommonJS (require)

```js
const csvToMarkdown = require("csv-to-markdown-table");

console.log(
  csvToMarkdown("Name,Role,Location\nAda Lovelace,Mathematician,London\nGrace Hopper,Computer scientist,New York", ",", true)
);
```

### Node.js with ES Modules (import)

```js
import csvToMarkdown from "csv-to-markdown-table";

console.log(
  csvToMarkdown("Name,Role,Location\nAda Lovelace,Mathematician,London\nGrace Hopper,Computer scientist,New York", ",", true)
);
```

### TypeScript

```ts
import csvToMarkdown from "csv-to-markdown-table";

console.log(
  csvToMarkdown("Name,Role,Location\nAda Lovelace,Mathematician,London\nGrace Hopper,Computer scientist,New York", ",", true)
);
```

#### Outputs:

```markdown
| Name         | Role               | Location |
|--------------|--------------------|----------|
| Ada Lovelace | Mathematician      | London   |
| Grace Hopper | Computer scientist | New York |
```

Which displays in markdown as:

| Name         | Role               | Location |
|--------------|--------------------|----------|
| Ada Lovelace | Mathematician      | London   |
| Grace Hopper | Computer scientist | New York |


### Options

The optional fourth argument accepts conversion settings:

```js
csvToMarkdown('name,quote\nAda,"line one\nline two"', ",", true, {
  newlineReplacement: "<br />",
  cellFilter: (value) => value.trim(),
});
```

`enclosure` and `escape` are optional strings passed to csv-walker
when supplied. Omitting them retains csv-walker's defaults: `enclosure` is `"`,
and `escape` is `\`. Enclosure and escape must each be a
single character, except that `escape: ""` disables CSV escaping.

```js
csvToMarkdown("'name','note'\n'Ada','hello, world'", ",", true, {
  enclosure: "'",
  escape: "",
});
```

`newlineReplacement` sets the string used for newlines within CSV fields
(LF, CR, or CRLF). It defaults to `"<br>"`; use `""` to remove them or `null`
to skip newline replacement and preserve the original newline characters.
Existing calls without options retain the same behavior. TypeScript users can
import the `CsvToMarkdownOptions` type; the argument accepts
`Partial<CsvToMarkdownOptions>` so each setting can be supplied independently.

```ts
import type { CsvToMarkdownOptions } from "csv-to-markdown-table";
```

`cellFilter` accepts a `(value: string, rowIndex: number, columnIndex: number) => string` callback to transform each
parsed CSV field, including headers and empty fields. It runs before tab and
newline replacement, Markdown escaping, and column sizing. By default, values
are returned unchanged.

Indexes are zero-based and refer to parsed CSV rows and columns, including the
header row. Callbacks can ignore either or both indexes. For example, to uppercase
only the first row:

```js
csvToMarkdown(csv, ",", true, {
  cellFilter: (value, rowIndex) => rowIndex === 0 ? value.toUpperCase() : value,
});
```

Supplied options are merged with the defaults. Omit a property to use its default
value; explicitly setting a property to `undefined` is unsupported. TypeScript
users can enable `exactOptionalPropertyTypes` to catch this at compile time.

`prettyPrint` defaults to `true`, padding cells to align columns. Set it to
`false` for compact output with outer pipes and three-dash separators. Spaces
within cell values are preserved.

Both modes use the same input:

```js
const csv = [
  "Name,Role,Location",
  "Ada Lovelace,Mathematician,London",
  "Grace Hopper,Computer scientist,New York",
].join("\n");

csvToMarkdown(csv, ",", true); // prettyPrint: true (default)
csvToMarkdown(csv, ",", true, { prettyPrint: false });
```

With `prettyPrint: true`, columns line up in the Markdown source:

```markdown
| Name         | Role               | Location |
|--------------|--------------------|----------|
| Ada Lovelace | Mathematician      | London   |
| Grace Hopper | Computer scientist | New York |
```

With `prettyPrint: false`, only the cell content and table delimiters remain:

```markdown
|Name|Role|Location|
|---|---|---|
|Ada Lovelace|Mathematician|London|
|Grace Hopper|Computer scientist|New York|
```

Both render as the same table.

## Distribution Formats

This package is distributed in multiple formats:

- **UMD**: Universal Module Definition for browsers and legacy environments (includes csvToMarkdown global variable when loaded in a browser)
  - `lib/CsvToMarkdown.js` (unminified)
  - `lib/CsvToMarkdown.min.js` (minified)
- **ESM**: ES Modules for modern JavaScript environments
  - `lib/CsvToMarkdown.mjs`
- **CJS**: CommonJS for Node.js
  - `lib/CsvToMarkdown.cjs`

The package.json is configured with the appropriate fields to ensure the correct format is used in each environment:

- `main`: Points to the CommonJS build
- `module`: Points to the ESM build
- `unpkg`: Points to the minified UMD build
- `exports`: Provides conditional exports for different environments

---
_Source: https://npm.io/package/csv-to-markdown-table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
