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.2.0 to 2.3.0

163

index.d.ts

@@ -1,25 +0,146 @@

declare module 'csv-parser' {
import { Transform } from 'stream';
/// <reference types="node"/>
import { Transform } from 'stream';
interface CsvParser extends Transform {}
interface CsvParserOptions {
escape?: string;
headers?: ReadonlyArray<string> | boolean;
mapHeaders?: (args: { header: string; index: number }) => string | null;
mapValues?: (args: { header: string; index: number; value: any }) => any;
newline?: string;
quote?: string;
raw?: boolean;
separator?: string;
skipComments?: number | string;
skipLines?: number;
maxRowBytes?: number;
strict?: boolean;
declare namespace csvParser {
type CsvParser = Transform;
interface Options {
/**
* A single-character string used to specify the character used to escape strings in a CSV row.
*
* @default '"'
*/
readonly escape?: string;
/**
* Specifies the headers to use. Headers define the property key for each value in a CSV row. If no `headers` option is provided, `csv-parser` will use the first line in a CSV file as the header specification.
*
* If `false`, specifies that the first row in a data file does _not_ contain headers, and instructs the parser to use the row index as the key for each row.
*
* Suppose you have a CSV file `data.csv` which contains the data:
*
* ```
NAME,AGE
Daffy Duck,24
Bugs Bunny,22
```
* Using `headers: false` with the data from `data.csv` would yield:
* ```
[
{ '0': 'Daffy Duck', '1': 24 },
{ '0': 'Bugs Bunny', '1': 22 }
]
```
*/
readonly headers?: ReadonlyArray<string> | boolean;
/**
* A function that can be used to modify the values of each header. Return `null` to remove the header, and it's column, from the results.
*
* @example
*
* csv({
* mapHeaders: ({ header, index }) => header.toLowerCase()
* });
*/
readonly mapHeaders?: (args: { header: string; index: number }) => string | null;
/**
* A function that can be used to modify the value of each column value.
*
* @example
*
* csv({
* mapValues: ({ header, index, value }) => value.toLowerCase()
* });
*/
readonly mapValues?: (args: { header: string; index: number; value: any }) => any;
/**
* Specifies a single-character string to denote the end of a line in a CSV file.
*
* @default '\n'
*/
readonly newline?: string;
/**
* Specifies a single-character string to denote a quoted string.
*
* @default '"'
*/
readonly quote?: string;
/**
* If `true`, instructs the parser not to decode UTF-8 strings.
*/
readonly raw?: boolean;
/**
* Specifies a single-character string to use as the column separator for each row.
*
* @default ','
*/
readonly separator?: string;
/**
* 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.
*
* @default false
*/
readonly skipComments?: boolean | string;
/**
* Specifies the number of lines at the beginning of a data file that the parser should skip over, prior to parsing headers.
*
* @default 0
*/
readonly skipLines?: number;
/**
* Maximum number of bytes per row. An error is thrown if a line exeeds this value. The default value is on 8 peta byte.
*
* @default Number.MAX_SAFE_INTEGER
*/
readonly maxRowBytes?: number;
/**
* If `true`, instructs the parser that the number of columns in each row must match the number of `headers` specified.
*/
readonly strict?: boolean;
}
}
const csvParser: (
optionsOrHeaders?: CsvParserOptions | ReadonlyArray<string>
) => CsvParser;
/**
* Streaming CSV parser that aims for maximum speed as well as compatibility with the [csv-spectrum](https://npmjs.org/csv-spectrum) CSV acid test suite.
*
* @param optionsOrHeaders - As an alternative to passing an `options` object, you may pass an `Array[String]` which specifies the headers to use. If you need to specify options _and_ headers, please use the the object notation with the `headers` property.
*
* @example
*
* // data.csv:
* //
* // NAME,AGE
* // Daffy Duck,24
* // Bugs Bunny,22
*
* import csv = require('csv-parser');
* import * as fs from 'fs';
*
* const results = [];
*
* fs.createReadStream('data.csv')
* .pipe(csv())
* .on('data', (data) => results.push(data))
* .on('end', () => {
* console.log(results);
* // [
* // { NAME: 'Daffy Duck', AGE: '24' },
* // { NAME: 'Bugs Bunny', AGE: '22' }
* // ]
* });
*/
declare const csvParser: (
optionsOrHeaders?: csvParser.Options | ReadonlyArray<string>
) => csvParser.CsvParser;
export = csvParser;
}
export = csvParser;

2

index.js

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

if (buf[end - 1] === comma) {
cells.push(this._empty)
cells.push(mapValue(this._empty))
}

@@ -186,0 +186,0 @@

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

@@ -28,6 +28,5 @@ "license": "MIT",

"commitlint": "commitlint",
"commitmsg": "commitlint -e $GIT_PARAMS",
"lint": "eslint .",
"lint-staged": "lint-staged",
"test": "ava"
"test": "ava && tsd"
},

@@ -44,24 +43,26 @@ "dependencies": {

"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"ava": "^0.25.0",
"bops": "^0.1.1",
"chalk": "^2.4.1",
"concat-stream": "^1.4.5",
"@commitlint/cli": "^7.6.1",
"@commitlint/config-conventional": "^7.6.0",
"@types/node": "^12.0.0",
"ava": "^1.4.1",
"bops": "^1.0.0",
"chalk": "^2.4.2",
"concat-stream": "^2.0.0",
"csv-spectrum": "^1.0.0",
"eslint": "^5.4.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^3.1.0",
"globby": "^8.0.1",
"husky": "^0.14.3",
"lint-staged": "^7.2.0",
"loud-rejection": "^1.6.0",
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-node": "^9.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"globby": "^9.2.0",
"husky": "^2.2.0",
"lint-staged": "^8.1.6",
"loud-rejection": "^2.1.0",
"pre-commit": "^1.2.2",
"standard-version": "^4.4.0",
"strip-ansi": "^4.0.0",
"standard-version": "^6.0.1",
"strip-ansi": "^5.2.0",
"text-table": "^0.2.0",
"time-span": "^2.0.0"
"time-span": "^3.1.0",
"tsd": "^0.7.3"
},

@@ -84,3 +85,8 @@ "directories": {

]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
}
}

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

### csv([options|headers])
### csv([options | headers])
Returns: `Array[object]`
Returns: `Array[Object]`
#### options
Type: `object`
Type: `Object`

@@ -144,3 +144,3 @@ As an alternative to passing an `options` object, you may pass an `Array[String]`

Type: `Array[String]|boolean`
Type: `Array[String] | Boolean`

@@ -147,0 +147,0 @@ Specifies the headers to use. Headers define the property key for each value in

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