1.8.0 • Published 5 months ago

@woocommerce/csv-export v1.8.0

Weekly downloads
936
License
GPL-3.0-or-later
Repository
github
Last release
5 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.
	// 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

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

5 months ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago