save-csv
v4.1.0
Published
Download an array of objects as a CSV file in the browser
Maintainers
Readme
save-csv
Download an array of objects as a CSV file in the browser
save-csv is a tiny library (892 bytes gzipped) that creates an CSV file from a array of objects with matching keys and triggers a download in the browser. Features:
- Automatically detects the value separator (usually
,) based on the user's regional settings. - Saves UTF8 by default and helps Excel to recognize this by adding a byte order mark.
- Fully configurable. Every output character can be modified via options.
Example
<script src="save-csv.min.js"></script>saveCsv([
{a:1, b:2},
{a:3, b:4},
]);Output
a,b
1,2
3,4API
save-csv(array, [options])
arrayArray: An array containing objects with matching keys.optionsObjectfilenamestring: The filename to save to. Default:export.csv.sepstring: The value separator (usually,). Recognizes the special valueautowith which automatic detection based on the user's regional settings is attempted (See #1). Default:auto.eolstring: The line separator. Default:\r\n.quotestring: The quote character to use. Default:".bomboolean: Whether to include a byte order mark in the output. Default:true.mimestring: The mime type for the file. Default:text/csv;charset=utf-8.formatterFunction: A custom formatter function for values. The default function handlessepin values and usesJSON.stringify for complex values. Receivesvalue`.
© silverwind, distributed under BSD licence
