Socket
Socket
Sign inDemoInstall

csv-parser

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-parser - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

index.d.ts

13

index.js

@@ -18,2 +18,3 @@ const { Transform } = require('stream')

separator: ',',
skipComments: false,
skipLines: null,

@@ -136,2 +137,10 @@ maxRowBytes: Number.MAX_SAFE_INTEGER,

const { skipComments } = this
if (skipComments) {
const char = typeof skipComments === 'string' ? skipComments : '#'
if (buf[start] === bufferFrom(char)[0]) {
return
}
}
const mapValue = (value) => {

@@ -179,3 +188,3 @@ if (this._first) {

const skip = this.skipLines && this.skipLines !== this._line
const skip = this.skipLines && this.skipLines > this._line
this._line++

@@ -195,3 +204,3 @@

} else {
if (!this._first) this._emit(this._Row, cells)
if (!skip) this._emit(this._Row, cells)
}

@@ -198,0 +207,0 @@ }

7

package.json
{
"name": "csv-parser",
"version": "2.1.0",
"version": "2.2.0",
"description": "Streaming CSV parser that aims for maximum speed as well as compatibility with the csv-spectrum test suite",

@@ -19,3 +19,4 @@ "license": "MIT",

"bin/csv-parser",
"index.js"
"index.js",
"index.d.ts"
],

@@ -31,3 +32,3 @@ "engines": {

"lint-staged": "lint-staged",
"test": "ava test/test.js"
"test": "ava"
},

@@ -34,0 +35,0 @@ "dependencies": {

@@ -82,5 +82,5 @@ [tests]: http://img.shields.io/travis/mafintosh/csv-parser.svg

```
NAME, AGE
Daffy Duck, 24
Bugs Bunny, 22
NAME,AGE
Daffy Duck,24
Bugs Bunny,22
```

@@ -97,8 +97,8 @@

.pipe(csv())
.on('data', results.push)
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
// [
// { NAME: 'Daffy Duck', AGE: 24 },
// { NAME: 'Bugs Bunny', AGE: 22 }
// { NAME: 'Daffy Duck', AGE: '24' },
// { NAME: 'Bugs Bunny', AGE: '22' }
// ]

@@ -171,3 +171,3 @@ });

csv({
mapHeader: ({ header, index }) => header.toLowerCase();
mapHeaders: ({ header, index }) => header.toLowerCase()
})

@@ -184,3 +184,3 @@ ```

csv({
mapHeader: ({ header, index, value }) => value.toLowerCase();
mapValues: ({ header, index, value }) => value.toLowerCase()
})

@@ -216,2 +216,9 @@ ```

##### skipComments
Type: `Boolean | String`<br>
Default: `false`
Instructs the parser to ignore lines which represent comments in a CSV file. Since there is no specification that dictates what a CSV comment looks like, comments should be considered non-standard. The "most common" character used to signify a comment in a CSV file is `"#"`. If this option is set to `true`, lines which begin with `#` will be skipped. If a custom character is needed to denote a commented line, this option may be set to a string which represents the leading character(s) signifying a comment line.
##### skipLines

@@ -283,2 +290,3 @@

--separator,-s Set the separator character ("," by default)
--skipComments,-c Skip CSV comments that begin with '#'. Set a value to change the comment character.
--skipLines,-l Set the number of lines to skip to before parsing headers

@@ -305,2 +313,28 @@ --strict Require column length match headers length

## Byte Order Marks
Some CSV files may be generated with, or contain a leading [Byte Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8). This may cause issues parsing headers and/or data from your file. From Wikipedia:
>The Unicode Standard permits the BOM in UTF-8, but does not require nor recommend its use. Byte order has no meaning in UTF-8.
To use this module with a file containing a BOM, please use a module like [strip-bom-stream](https://github.com/sindresorhus/strip-bom-stream) in your pipeline:
```js
const fs = require('fs');
const csv = require('csv-parser');
const stripBom = require('strip-bom-stream');
fs.createReadStream('data.csv')
.pipe(stripBomStream())
.pipe(csv())
...
```
When using the CLI, the BOM can be removed by first running:
```console
$ sed $'s/\xEF\xBB\xBF//g' data.csv
```
## Meta

@@ -307,0 +341,0 @@

Sorry, the diff of this file is not supported yet

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