Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/silverwind/save-csv
Download an array of objects as a CSV file in the browser
https://github.com/silverwind/save-csv
browser csv csv-download csv-export javascript
Last synced: 2 months ago
JSON representation
Download an array of objects as a CSV file in the browser
- Host: GitHub
- URL: https://github.com/silverwind/save-csv
- Owner: silverwind
- License: bsd-2-clause
- Created: 2017-08-06T22:35:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-24T20:46:07.000Z (about 6 years ago)
- Last Synced: 2024-11-02T06:53:39.670Z (3 months ago)
- Topics: browser, csv, csv-download, csv-export, javascript
- Language: JavaScript
- Size: 155 KB
- Stars: 13
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# save-csv
[![](https://img.shields.io/npm/v/save-csv.svg?style=flat)](https://www.npmjs.org/package/save-csv) [![](https://img.shields.io/npm/dm/save-csv.svg)](https://www.npmjs.org/package/save-csv) [![](https://api.travis-ci.org/silverwind/save-csv.svg?style=flat)](https://travis-ci.org/silverwind/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](https://en.wikipedia.org/wiki/Byte_order_mark).
- Fully configurable. Every output character can be modified via options.## Example
```html```
```js
saveCsv([
{a:1, b:2},
{a:3, b:4},
]);
```
#### Output
```csv
a,b
1,2
3,4
```## API
### save-csv(array, [options])
- `array` *Array*: An array containing objects with matching keys.
- `options` *Object*
- `filename` *string*: The filename to save to. Default: `export.csv`.
- `sep` *string*: The value separator (usually `,`). Recognizes the special value `auto` with which automatic detection based on the user's regional settings is attempted (See [#1](https://github.com/silverwind/save-csv/issues/1)). Default: `auto`.
- `eol` *string*: The line separator. Default: `\r\n`.
- `quote` *string*: The quote character to use. Default: `"`.
- `bom` *boolean*: Whether to include a [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark) in the output. Default: `true`.
- `mime` *string*: The mime type for the file. Default: `text/csv;charset=utf-8`.
- `formatter` *Function*: A custom formatter function for values. The default function handles `sep` in values and uses `JSON.stringify` for complex values. Receives `value`.© [silverwind](https://github.com/silverwind), distributed under BSD licence