# @woocommerce/csv-export

> WooCommerce utility library to convert data to CSV files.

Latest version **1.11.0** (published 2026-06-10) · GPL-2.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @woocommerce/csv-export
pnpm add @woocommerce/csv-export
yarn add @woocommerce/csv-export
bun add @woocommerce/csv-export
```

## Health

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

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.11.0 |
| Published | 2026-06-10 |
| First published | 2018-11-15 |
| Weekly downloads | 0 |
| License | GPL-2.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^24.15.0 |
| Dependencies | 2 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 10577 |
| Author | Automattic |
| Maintainers | mikejolley, albertjuhe, nerrad, obliviousharmony, louwie17, chihsuan, ~woocommerce, zhongruige, opr, kraftbj |
| Keywords | wordpress, woocommerce, csv |

## Links

- npm: https://www.npmjs.com/package/@woocommerce/csv-export
- Repository: https://github.com/woocommerce/woocommerce
- Homepage: https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/csv-export/README.md
- Issues: https://github.com/woocommerce/woocommerce/issues
- npm.io page: https://npm.io/package/@woocommerce/csv-export

## Dependencies (2)

- [@types/node](https://npm.io/package/@types/node.md) ^24.1.0
- [browser-filesaver](https://npm.io/package/browser-filesaver.md) ^1.1.1

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@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

## Recent versions

- 1.11.0 (latest) — 2026-06-10
- 1.0.0 (next) — 2018-11-15
- 1.10.0 — 2024-12-22
- 1.9.0 — 2024-06-11
- 1.8.0 — 2023-11-28
- 1.7.0 — 2022-07-08
- 1.6.0 — 2022-06-15
- 1.5.0 — 2022-03-23
- 1.4.0 — 2021-08-10
- 1.3.2 — 2021-06-23
- 1.3.1 — 2021-04-12
- 1.3.0 — 2020-08-04
- 1.2.0 — 2019-12-02
- 1.1.2 — 2019-08-15
- 1.1.1 — 2019-07-04
- … 4 more at https://npm.io/package/@woocommerce/csv-export/versions

## README

# CSV Export

A set of functions to convert data into CSV values, and enable a browser download of the CSV data.

## Installation

Install the module

```bash
pnpm install @woocommerce/csv-export --save
```

## Usage

```js
onClick = () => {
	// Create a file name based on a title and optional query. Will return a timestamped
	// name, for example: revenue-2018-11-01-interval-month.csv
	const name = generateCSVFileName( 'revenue', { interval: 'month' } );

	// Create a string of CSV data, `headers` is an array of row headers, put at the top
	// of the file. `rows` is a 2 dimensional array. Each array is a line in the file,
	// separated by newlines. The second-level arrays are the data points in each row.
	const data = generateCSVDataFromTable( headers, rows );

	// Triggers a browser UI to save a file, named the first argument, with the contents of
	// the second argument.
	downloadCSVFile( name, data );
}
```

### generateCSVDataFromTable(headers, rows) ⇒ `String`

Generates a CSV string from table contents

**Returns**: `String` - Table contents in a CSV format

| Param | Type | Description |
| --- | --- | --- |
| headers | `Array.&lt;Object&gt;` | Object with table header information |
| rows | `Array.Array.&lt;Object&gt;` | Object with table rows information |

### generateCSVFileName([name], [params]) ⇒ `String`

Generates a file name for CSV files based on the provided name, the current date
and the provided params, which are all appended with hyphens.

**Returns**: `String` - Formatted file name

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [name] | `String` | `&#x27;&#x27;` | Name of the file |
| [params] | `Object` | `{}` | Object of key-values to append to the file name |

### downloadCSVFile(fileName, content)

Downloads a CSV file with the given file name and contents

| Param | Type | Description |
| --- | --- | --- |
| fileName | `String` | Name of the file to download |
| content | `String` | Contents of the file to download |

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