4.1.0 • Published 5 years ago

save-csv v4.1.0

Weekly downloads
760
License
BSD-2-Clause
Repository
github
Last release
5 years ago

save-csv

npm.io npm.io npm.io

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,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). 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 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. Receivesvalue`.

© silverwind, distributed under BSD licence

4.1.0

5 years ago

4.0.7

6 years ago

4.0.6

6 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago