Socket
Socket
Sign inDemoInstall

csv-parse

Package Overview
Dependencies
Maintainers
1
Versions
141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-parse - npm Package Compare versions

Comparing version 4.3.4 to 4.4.0

samples/option.bom.js

9

CHANGELOG.md

@@ -10,2 +10,7 @@

## Version 4.4.0
New features:
* options: new bom option
## Version 4.3.4

@@ -124,3 +129,3 @@

* src: precompute escapeIsQuote
* travis: test agains Node.js 11
* travis: test against Node.js 11

@@ -205,3 +210,3 @@ ## Version 3.1.3

* package: es5 backward compatiblity
* package: es5 backward compatibility
* package: ignore yarn lock file

@@ -208,0 +213,0 @@

@@ -52,3 +52,2 @@ // Original definitions in https://github.com/DefinitelyTyped/DefinitelyTyped by: David Muller <https://github.com/davidm77>

auto_parse?: boolean | CastingFunction;
/**

@@ -59,4 +58,7 @@ * If true, the parser will attempt to convert read data types to dates. It requires the "auto_parse" option.

auto_parse_date?: boolean | CastingDateFunction;
/**
* If true, detect and exclude the byte order mark (BOM) from the CSV input if present.
*/
bom?: boolean;
/**
* If true, the parser will attempt to convert input string to native types.

@@ -66,3 +68,2 @@ * If a function, receive the value as first argument, a context as second argument and return a new value. More information about the context properties is available below.

cast?: boolean | CastingFunction;
/**

@@ -73,3 +74,2 @@ * If true, the parser will attempt to convert input string to dates.

cast_date?: boolean | CastingDateFunction;
/**

@@ -82,3 +82,2 @@ * List of fields as an array,

columns?: any[] | boolean | ((record: any) => boolean | string[]);
/**

@@ -88,3 +87,2 @@ * Treat all the characters after this one as a comment, default to '' (disabled).

comment?: string;
/**

@@ -94,3 +92,2 @@ * Set the field delimiter. One character only, defaults to comma.

delimiter?: string | Buffer;
/**

@@ -100,3 +97,2 @@ * Set the escape character, one character only, defaults to double quotes.

escape?: string | Buffer;
/**

@@ -106,3 +102,2 @@ * Start handling records from the requested number of records.

from?: number;
/**

@@ -112,3 +107,2 @@ * Start handling records from the requested line number.

from_line?: number;
/**

@@ -118,3 +112,2 @@ * Generate two properties `info` and `record` where `info` is a snapshot of the info object at the time the record was created and `record` is the parsed array or object.

info?: boolean;
/**

@@ -125,3 +118,2 @@ * If true, ignore whitespace immediately following the delimiter (i.e. left-trim all fields), defaults to false.

ltrim?: boolean;
/**

@@ -133,3 +125,2 @@ * Maximum numer of characters to be contained in the field and line buffers before an exception is raised,

max_record_size?: number;
/**

@@ -139,3 +130,2 @@ * Name of header-record title to name objects by.

objname?: string;
/**

@@ -145,3 +135,2 @@ * Optional character surrounding a field, one character only, defaults to double quotes.

quote?: string | boolean | Buffer;
/**

@@ -151,3 +140,2 @@ * Generate two properties raw and row where raw is the original CSV row content and row is the parsed array or object.

raw?: boolean;
/**

@@ -157,3 +145,2 @@ * Preserve quotes inside unquoted field.

relax?: boolean;
/**

@@ -163,3 +150,2 @@ * Discard inconsistent columns count, default to false.

relax_column_count?: boolean;
/**

@@ -170,3 +156,2 @@ * One or multiple characters used to delimit record rows; defaults to auto discovery if not provided.

record_delimiter?: string | string[] | Buffer | Buffer[];
/**

@@ -177,3 +162,2 @@ * If true, ignore whitespace immediately preceding the delimiter (i.e. right-trim all fields), defaults to false.

rtrim?: boolean;
/**

@@ -184,3 +168,2 @@ * Dont generate empty values for empty lines.

skip_empty_lines?: boolean;
/**

@@ -190,3 +173,2 @@ * Skip a line with error found inside and directly go process the next line.

skip_lines_with_error?: boolean;
/**

@@ -196,3 +178,2 @@ * Don't generate records for lines containing empty column values (column matching /\s*\/), defaults to false.

skip_lines_with_empty_values?: boolean;
/**

@@ -202,3 +183,2 @@ * Stop handling records after the requested number of records.

to?: number;
/**

@@ -208,3 +188,2 @@ * Stop handling records after the requested line number.

to_line?: number;
/**

@@ -211,0 +190,0 @@ * If true, ignore whitespace immediately around the delimiter, defaults to false.

@@ -56,2 +56,3 @@ "use strict";

var tab = 9;
var bom_utf8 = Buffer.from([239, 97, 191]);

@@ -77,2 +78,9 @@ var Parser =

options[underscore(opt)] = opts[opt];
} // Normalize option `bom`
if (options.bom === undefined || options.bom === null || options.bom === false) {
options.bom = false;
} else if (options.bom !== true) {
throw new Error("Invalid Option: bom must be true, got ".concat(JSON.stringify(options.bom)));
} // Normalize option `cast`

@@ -452,2 +460,3 @@

var _this$options = this.options,
bom = _this$options.bom,
comment = _this$options.comment,

@@ -477,6 +486,12 @@ escape = _this$options.escape,

if (nextBuf === undefined) {
// Handle empty string
this.push(null);
return;
} else {
buf = nextBuf;
// Handle UTF BOM
if (bom === true && bom_utf8.compare(nextBuf, 0, 3)) {
buf = nextBuf.slice(3);
} else {
buf = nextBuf;
}
}

@@ -490,3 +505,3 @@ } else if (previousBuf !== undefined && nextBuf === undefined) {

var bufLen = buf.length;
var pos; // let escaping = this.
var pos;

@@ -493,0 +508,0 @@ for (pos = 0; pos < bufLen; pos++) {

@@ -52,3 +52,2 @@ // Original definitions in https://github.com/DefinitelyTyped/DefinitelyTyped by: David Muller <https://github.com/davidm77>

auto_parse?: boolean | CastingFunction;
/**

@@ -59,4 +58,7 @@ * If true, the parser will attempt to convert read data types to dates. It requires the "auto_parse" option.

auto_parse_date?: boolean | CastingDateFunction;
/**
* If true, detect and exclude the byte order mark (BOM) from the CSV input if present.
*/
bom?: boolean;
/**
* If true, the parser will attempt to convert input string to native types.

@@ -66,3 +68,2 @@ * If a function, receive the value as first argument, a context as second argument and return a new value. More information about the context properties is available below.

cast?: boolean | CastingFunction;
/**

@@ -73,3 +74,2 @@ * If true, the parser will attempt to convert input string to dates.

cast_date?: boolean | CastingDateFunction;
/**

@@ -82,3 +82,2 @@ * List of fields as an array,

columns?: any[] | boolean | ((record: any) => boolean | string[]);
/**

@@ -88,3 +87,2 @@ * Treat all the characters after this one as a comment, default to '' (disabled).

comment?: string;
/**

@@ -94,3 +92,2 @@ * Set the field delimiter. One character only, defaults to comma.

delimiter?: string | Buffer;
/**

@@ -100,3 +97,2 @@ * Set the escape character, one character only, defaults to double quotes.

escape?: string | Buffer;
/**

@@ -106,3 +102,2 @@ * Start handling records from the requested number of records.

from?: number;
/**

@@ -112,3 +107,2 @@ * Start handling records from the requested line number.

from_line?: number;
/**

@@ -118,3 +112,2 @@ * Generate two properties `info` and `record` where `info` is a snapshot of the info object at the time the record was created and `record` is the parsed array or object.

info?: boolean;
/**

@@ -125,3 +118,2 @@ * If true, ignore whitespace immediately following the delimiter (i.e. left-trim all fields), defaults to false.

ltrim?: boolean;
/**

@@ -133,3 +125,2 @@ * Maximum numer of characters to be contained in the field and line buffers before an exception is raised,

max_record_size?: number;
/**

@@ -139,3 +130,2 @@ * Name of header-record title to name objects by.

objname?: string;
/**

@@ -145,3 +135,2 @@ * Optional character surrounding a field, one character only, defaults to double quotes.

quote?: string | boolean | Buffer;
/**

@@ -151,3 +140,2 @@ * Generate two properties raw and row where raw is the original CSV row content and row is the parsed array or object.

raw?: boolean;
/**

@@ -157,3 +145,2 @@ * Preserve quotes inside unquoted field.

relax?: boolean;
/**

@@ -163,3 +150,2 @@ * Discard inconsistent columns count, default to false.

relax_column_count?: boolean;
/**

@@ -170,3 +156,2 @@ * One or multiple characters used to delimit record rows; defaults to auto discovery if not provided.

record_delimiter?: string | string[] | Buffer | Buffer[];
/**

@@ -177,3 +162,2 @@ * If true, ignore whitespace immediately preceding the delimiter (i.e. right-trim all fields), defaults to false.

rtrim?: boolean;
/**

@@ -184,3 +168,2 @@ * Dont generate empty values for empty lines.

skip_empty_lines?: boolean;
/**

@@ -190,3 +173,2 @@ * Skip a line with error found inside and directly go process the next line.

skip_lines_with_error?: boolean;
/**

@@ -196,3 +178,2 @@ * Don't generate records for lines containing empty column values (column matching /\s*\/), defaults to false.

skip_lines_with_empty_values?: boolean;
/**

@@ -202,3 +183,2 @@ * Stop handling records after the requested number of records.

to?: number;
/**

@@ -208,3 +188,2 @@ * Stop handling records after the requested line number.

to_line?: number;
/**

@@ -211,0 +190,0 @@ * If true, ignore whitespace immediately around the delimiter, defaults to false.

@@ -16,2 +16,3 @@

const tab = 9
const bom_utf8 = Buffer.from([239, 97, 191])

@@ -26,2 +27,8 @@ class Parser extends Transform {

}
// Normalize option `bom`
if(options.bom === undefined || options.bom === null || options.bom === false){
options.bom = false
}else if(options.bom !== true){
throw new Error(`Invalid Option: bom must be true, got ${JSON.stringify(options.bom)}`)
}
// Normalize option `cast`

@@ -351,3 +358,3 @@ let fnCastField = null

__parse(nextBuf, end){
const {comment, escape, from, from_line, info, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options
const {bom, comment, escape, from, from_line, info, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options
let {record_delimiter} = this.options

@@ -358,6 +365,12 @@ const {previousBuf, rawBuffer, escapeIsQuote, trimChars} = this.state

if(nextBuf === undefined){
// Handle empty string
this.push(null)
return
}else{
buf = nextBuf
// Handle UTF BOM
if(bom === true && bom_utf8.compare(nextBuf, 0, 3)){
buf = nextBuf.slice(3)
}else{
buf = nextBuf
}
}

@@ -371,3 +384,2 @@ }else if(previousBuf !== undefined && nextBuf === undefined){

let pos
// let escaping = this.
for(pos = 0; pos < bufLen; pos++){

@@ -374,0 +386,0 @@ // Ensure we get enough space to look ahead

{
"version": "4.3.4",
"version": "4.4.0",
"name": "csv-parse",

@@ -38,9 +38,9 @@ "description": "CSV parsing implementing the Node.js `stream.Transform` API",

"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@types/mocha": "^5.2.6",
"@types/node": "^11.11.0",
"@types/node": "^11.13.0",
"@types/should": "^13.0.0",
"coffeescript": "^2.3.2",
"coffeescript": "^2.4.0",
"csv-generate": "^3.2.0",

@@ -53,3 +53,3 @@ "csv-spectrum": "^1.0.0",

"ts-node": "^8.0.3",
"typescript": "^3.3.3333"
"typescript": "^3.4.2"
},

@@ -56,0 +56,0 @@ "optionalDependencies": {},

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