1.10.0 • Published 6 months ago

@woocommerce/csv-export v1.10.0

Weekly downloads
936
License
GPL-3.0-or-later
Repository
github
Last release
6 months ago

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.
	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

ParamTypeDescription
headersArray.<Object>Object with table header information
rowsArray.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

ParamTypeDefaultDescription
nameString''Name of the file
paramsObject{}Object of key-values to append to the file name

downloadCSVFile(fileName, content)

Downloads a CSV file with the given file name and contents

ParamTypeDescription
fileNameStringName of the file to download
contentStringContents of the file to download
1.10.0

6 months ago

1.9.0

1 year ago

1.8.0

2 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

5 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago