New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@alesmenzel/csv

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alesmenzel/csv

CSV parser

latest
npmnpm
Version
1.5.0
Version published
Weekly downloads
6
-50%
Maintainers
1
Weekly downloads
 
Created
Source

@alesmenzel/csv

CI

Simple and elegant streaming csv parser.

Handles formats defined by RFC4180 but also works with format produced by PHP's fputcsv. Note in mind, that there is no defacto standard for CSV and different csv libraries create slightly different versions, for example some of them

  • use comments in csv # this is a comment (see relaxComments and comment options)
  • use escaping character instead of double quoting "\"" (this is valid csv cell in PHP's version, handled by default)
  • use blank spaces after quoted fields "abc" ,"cde" (see relaxCharactersAfterQuotedText option)
  • output different column count per each row (see relaxColumnCount option)
  • Byte Order Mark (BOM) at the start of CSV (see bom option)
  • do not contain the row delimiter (e.g. newline) on the last row (handled by default)

By default we are very strict about parsing the CSV, but can use the relax* rules to lower the bar.

Installation

npm i --save @alesmenzel/csv

Usage

const createCSVParser = require('@alesmenzel/csv')

const csv = new createCSVParser({
  // delimiter: ',' (default)
  // quote: '"' (default)
  // rowDelimiter: '\n' (default) - handles \r\n as well
  // escape: '\\' (default)
  // ... and other (see options below)
  // ... you can pass Transform stream options here - e.g. highWaterMark
})

const rows = []
csv.on('data', (row) => {
  rows.push(row)
})

csv.on('end', () => {
  console.log(rows)
})

csv.write('A,B,C\n')
csv.write('a,b,c\n')
csv.end('x,"Joe ""The Death"" Black",z\n')

Options

OptionDescriptionDefault Value
delimiterSingle character that is used to delimit the cells in a row.,
rowDelimiterSingle character that is used to delimit the rows in the input.\n (optionally preceded by \r)
quoteSingle character that is used to quote the value of a cell."
escapeSingle character that is used to escape a character inside the cell.\
commentSingle character that is used to define a comment line.#
bomStrip BOM from the first line of CSV if present.true
relaxCommentsAllow comments in CSV. Comments are lines that start with the comment character.false
relaxCharactersAfterQuotedTextAllow extranious characters after end of quoted cell, but those extra characters are ignored.false
relaxCommentsAllow comments in CSV. Comments are lines that start with the comment character.false
relaxColumnCountAllow inconsistent column count per each row.false
highWaterMark and other transform stream optionsOther options are passed to the underlaying Transform stream.-

Events

Besides the standard stream events, we emit the following:

Event "comment" (comment: string)

When a comment line is found. The payload is the actual comment string without the comment character (e.g. #).

csv.on('comment', (comment: string) => {
  // ...
})

Licence

This package is developed under the MIT licence.

Keywords

csv

FAQs

Package last updated on 21 Jan 2021

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