Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

export-to-csv

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

export-to-csv

Easily create CSV data from json collection

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
122K
decreased by-27.05%
Maintainers
1
Weekly downloads
 
Created

What is export-to-csv?

The export-to-csv npm package is a utility that allows you to easily export data to CSV format. It is particularly useful for converting JSON data into CSV files, which can then be downloaded or used in other applications.

What are export-to-csv's main functionalities?

Basic CSV Export

This feature allows you to export a basic JSON array to a CSV file. The code sample demonstrates how to configure the export options and generate the CSV data.

const { ExportToCsv } = require('export-to-csv');

const data = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Jane', age: 25, city: 'San Francisco' }
];

const options = {
  fieldSeparator: ',',
  quoteStrings: '"',
  decimalSeparator: '.',
  showLabels: true,
  showTitle: true,
  title: 'My CSV File',
  useTextFile: false,
  useBom: true,
  useKeysAsHeaders: true
};

const csvExporter = new ExportToCsv(options);
const csvData = csvExporter.generateCsv(data);
console.log(csvData);

Custom Headers

This feature allows you to specify custom headers for the CSV file. The code sample shows how to set the headers option to define the column names in the CSV output.

const { ExportToCsv } = require('export-to-csv');

const data = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Jane', age: 25, city: 'San Francisco' }
];

const options = {
  fieldSeparator: ',',
  quoteStrings: '"',
  decimalSeparator: '.',
  showLabels: true,
  showTitle: true,
  title: 'My CSV File',
  useTextFile: false,
  useBom: true,
  headers: ['Name', 'Age', 'City']
};

const csvExporter = new ExportToCsv(options);
const csvData = csvExporter.generateCsv(data);
console.log(csvData);

Download CSV File

This feature allows you to download the generated CSV data as a file. The code sample demonstrates how to use the 'fs' module to write the CSV data to a file.

const { ExportToCsv } = require('export-to-csv');
const fs = require('fs');

const data = [
  { name: 'John', age: 30, city: 'New York' },
  { name: 'Jane', age: 25, city: 'San Francisco' }
];

const options = {
  fieldSeparator: ',',
  quoteStrings: '"',
  decimalSeparator: '.',
  showLabels: true,
  showTitle: true,
  title: 'My CSV File',
  useTextFile: false,
  useBom: true,
  useKeysAsHeaders: true
};

const csvExporter = new ExportToCsv(options);
const csvData = csvExporter.generateCsv(data);
fs.writeFileSync('my_csv_file.csv', csvData);

Other packages similar to export-to-csv

Keywords

FAQs

Package last updated on 16 Aug 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc