Socket
Socket
Sign inDemoInstall

export-to-csv-fix-source-map

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    export-to-csv-fix-source-map

Easily create CSV data from json collection


Version published
Weekly downloads
9.1K
decreased by-4.41%
Maintainers
1
Install size
15.2 kB
Created
Weekly downloads
 

Readme

Source

export-to-csv | Export to CSV Mini Library

Based off of this library by Javier Telio

Helper library to quickly and easily create a CSV file in browser or Node

Installation

yarn add export-to-csv
// npm install --save export-to-csv

Usage


import { ExportToCsv } from 'export-to-csv';

var data = [
  {
    name: 'Test 1',
    age: 13,
    average: 8.2,
    approved: true,
    description: "using 'Content here, content here' "
  },
  {
    name: 'Test 2',
    age: 11,
    average: 8.2,
    approved: true,
    description: "using 'Content here, content here' "
  },
  {
    name: 'Test 4',
    age: 10,
    average: 8.2,
    approved: true,
    description: "using 'Content here, content here' "
  },
];

  const options = { 
    fieldSeparator: ',',
    quoteStrings: '"',
    decimalSeparator: '.',
    showLabels: true, 
    showTitle: true,
    title: 'My Awesome CSV',
    useTextFile: false,
    useBom: true,
    useKeysAsHeaders: true,
    // headers: ['Column 1', 'Column 2', etc...] <-- Won't work with useKeysAsHeaders present!
  };

const csvExporter = new ExportToCsv(options);

csvExporter.generateCsv(data);

API

OptionDefaultDescription
fieldSeparator,Defines the field separator character
filename'generated'Sets the name of the downloaded file. ".csv" will be appended to the value provided.
quoteStrings"If provided, will use this characters to "escape" fields, otherwise will use double quotes as deafult
decimalSeparator.Defines the decimal separator character (default is .). If set to "locale", it uses the language sensitive representation of the number.
showLabelsfalseIf true, the first row will be the headers option or object keys if useKeysAsHeaders is present
showTitlefalseIncludes the title as the first line in the generated file
title'My Generated Report'This string will be used as the report title
useBomtrueIf true, adds a BOM character at the start of the CSV to improve file compatibility
useTextFilefalseIf true, returns a .txt file instead of .csv
useKeysAsHeadersfalseIf true, this will use the keys of the first object in the collection as the column headers
headers[]Expects an array of strings, which if supplied, will be used as the column headers

Thanks!

Credits and Original Authors
javiertelioz
sn123
arf1980

Keywords

FAQs

Last updated on 17 Feb 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc