Socket
Socket
Sign inDemoInstall

@woocommerce/csv-export

Package Overview
Dependencies
Maintainers
16
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@woocommerce/csv-export

WooCommerce utility library to convert data to CSV files.


Version published
Weekly downloads
1.1K
decreased by-28.56%
Maintainers
16
Weekly downloads
 
Created
Source

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

npm 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
[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

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

Keywords

FAQs

Package last updated on 23 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc