GithubHelp home page GithubHelp logo

silverwind / save-csv Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 5.0 159 KB

Download an array of objects as a CSV file in the browser

License: BSD 2-Clause "Simplified" License

Makefile 31.14% JavaScript 68.86%
javascript csv csv-download csv-export browser

save-csv's Introduction

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,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. Receives value.

© silverwind, distributed under BSD licence

save-csv's People

Contributors

amcmillan01 avatar jeremysummers avatar silverwind avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

save-csv's Issues

It would be nice to set custom headers

Now items is an objects, and all key added as first row in csv with keys as values.
e.x. first_name.
sometimes these headings are not suitable for exporting. Especially when you need to make a multilingual application.

I can add the headers I need as the first line of data myself. But at the same time I can not disable the output of the first line with the keys.
It would be nice to add this feature to the options.
or if such an opportunity already exists, tell me how can i do it) Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.