0.0.5 • Published 3 years ago

mg-csv-writer v0.0.5

Weekly downloads
12
License
Apache-2.0
Repository
github
Last release
3 years ago

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
0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

4 years ago

0.0.2

5 years ago

0.0.1

5 years ago