woocommerce/packages/js/csv-export
Sam Seay 2db29164f9
Update to pnpm 9.1 (#47385)
* Update to pnpm 9.1 and fix a mini css bug

* Add changefile(s) from automation for the following project(s): @woocommerce/tracks, @woocommerce/product-editor, @woocommerce/onboarding, @woocommerce/number, @woocommerce/notices, @woocommerce/navigation, @woocommerce/internal-js-tests, @woocommerce/extend-cart-checkout-block, @woocommerce/expression-evaluation, @woocommerce/explat, @woocommerce/experimental, @woocommerce/eslint-plugin, @woocommerce/dependency-extraction-webpack-plugin, @woocommerce/date, @woocommerce/data, @woocommerce/customer-effort-score, @woocommerce/currency, @woocommerce/csv-export, @woocommerce/create-woo-extension, @woocommerce/create-product-editor-block, @woocommerce/components, @woocommerce/api, @woocommerce/ai, @woocommerce/admin-e2e-tests, woocommerce-blocks, woocommerce-beta-tester, woocommerce, woo-ai

* temporarily disable swallowing build output to diagnose issue with perf workflow

* Ignore some type issues that commonly resurface when deps slightly change

* Fix persistent type issues that have recurred many times

* Add more ignores

* Fix lint issue

* Revert change to swallow build error

* Improve access of the config that needs updated build dir.

---------

Co-authored-by: github-actions <github-actions@github.com>
2024-05-13 10:57:39 -03:00
..
changelog Update to pnpm 9.1 (#47385) 2024-05-13 10:57:39 -03:00
src Remove redundant dependency on moment in the csv-export package (#45410) 2024-03-12 17:06:53 +13:00
typings Update filesaver type 2022-05-20 10:51:52 +08:00
.eslintrc.js Add .eslintrc config to each packages 2022-03-29 16:08:07 +08:00
.npmrc Moved WCA Packages 2022-03-18 14:25:26 -07:00
.prettierrc.js Fix and consolidate linting across the monorepo (#35012) 2022-10-12 15:05:01 +13:00
CHANGELOG.md Prepare Packages for Release (#41657) 2023-11-28 20:47:14 +13:00
PREVIOUS_CHANGELOG.md Update JS packages changelogs (#33412) 2022-06-16 10:06:31 +12:00
README.md Moved WCA Packages 2022-03-18 14:25:26 -07:00
babel.config.js Update/unify jest@27 across all packages (#34322) 2022-09-06 09:29:45 -05:00
composer.json bump php version in packages/js/*/composer.json (#42020) 2024-01-04 10:18:34 -04:00
composer.lock Update changelogger to 3.3.0 to support PR number capturing with merge (#36266) 2023-01-05 14:42:51 +05:30
jest.config.json Fix Jest Preset (#42707) 2023-12-12 09:58:13 -08:00
package.json Update to pnpm 9.1 (#47385) 2024-05-13 10:57:39 -03:00
tsconfig-cjs.json Enforce Strict `@types` Dependencies (#37351) 2023-03-23 18:02:20 -07:00
tsconfig.json Update tsconfigs to explicitly include files to avoid TS build errors (#47156) 2024-05-07 13:18:56 +12:00

README.md

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

pnpm install @woocommerce/csv-export --save

Usage

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.
	// For header format, see https://woocommerce.github.io/woocommerce-admin/#/components/table?id=headers-2
	// For rows format, see https://woocommerce.github.io/woocommerce-admin/#/components/table?id=rows-1
	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.<Object> Object with table header information
rows Array.Array.<Object> 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 '' 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