Socket
Socket
Sign inDemoInstall

mg-csv-writer

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mg-csv-writer

Powerful, lean and flexible csv-writer for node


Version published
Weekly downloads
6
increased by20%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

csv-writer

A fast, lean CSV-WRITER for node that gives enough flexibility to create CSV files quickly and painlessly without too many hoops.

Features:

  • Optional CSV file write
  • Pagable results
  • async / await ready
  • Customizable delimiter
  • Customizable column control
    • Date formating
    • Type overriding
    • Value escaping
    • Callback function for ultimate control on formatting

Installation

npm install mg-csv-writer

Usage

var stockData = [{
		Symbol: "AAPL",
		Company: "Apple Inc.",
		Price: 132.5,
		TradeDt: new Date()
	},
	{
		Symbol: "INTC",
		Company: "Intel Corporation",
		Price: 33.45,
		TradeDt: new Date()
	},
	{
		Symbol: "GOOG",
		Company: "Google Inc",
		Price: 554.52,
		TradeDt: new Date()
	},
	{
		Symbol: "TLSA",
		Price: 554.52,
		TradeDt: new Date()
	}
];

const mgCsvWriter = require("mg-csv-writer");

const csvOut = new mgCsvWriter({
  outfile: "/tmp/output.csv",
  header: true,
  quoted: false,
  lineSep : "\n",
  delimiter: ",",
  columns: [{
      id: "Symbol",
      title: "Company Name",
      fnFormat: function(colData, colId, rowData) {
        // so something special!
        return colData;
      }
    },
    { id: "Company",
      title: "Id",
      defaultValue: "no name" },
    { id: "Price",
      title: "Price",
      dataType: "int",
      prefix: "$" },
    { id: "TradeDt",
      title: "Trade Date",
      dataType: "date",
      dateMask: "yyyy-mm-dd"
    }
  ]
});

csv.writeHeader();

csv.write(stockData);  // can be a single row; or an array of rows
csv.write(stockData2);  // multiple calls will add to the file

Updates

  • 2020-12-15 Renamed internal class; Updated code standard
  • 2020-02-13 Added quoted attribute
  • 2019-03-08 Initial Release

Keywords

FAQs

Last updated on 15 Dec 2020

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