Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.4.7 to 4.5.0

9

CHANGELOG.md

@@ -10,2 +10,11 @@

## Version 4.5.0
* errors: start normalizing errors with unique codes and context
* errors: expose CSV_INVALID_CLOSING_QUOTE
* errors: expose CSV_QUOTE_NOT_CLOSED
* errors: expose CSV_INVALID_RECORD_LENGTH_DONT_PREVIOUS_RECORDS
* errors: expose CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS
* errors: expose CSV_INVALID_COLUMN_MAPPING
## Version 4.4.7

@@ -12,0 +21,0 @@

59

lib/es5/index.js
"use strict";
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -609,3 +617,3 @@

} else if (relax === false) {
var err = this.__error("Invalid Closing Quote: got \"".concat(String.fromCharCode(nextChr), "\" at line ").concat(this.info.lines, " instead of delimiter, row delimiter, trimable character (if activated) or comment"));
var err = this.__error(new CsvError('CSV_INVALID_CLOSING_QUOTE', ['Invalid Closing Quote:', "got \"".concat(String.fromCharCode(nextChr), "\""), "at line ".concat(this.info.lines), 'instead of delimiter, row delimiter, trimable character', '(if activated) or comment'], {}));

@@ -729,3 +737,3 @@ if (err !== undefined) return err;

if (this.state.quoting === true) {
var _err4 = this.__error("Invalid Closing Quote: quote is not closed at line ".concat(this.info.lines));
var _err4 = this.__error(new CsvError('CSV_QUOTE_NOT_CLOSED', ['Quote Not Closed:', "the parsing is finished with an opening quote at line ".concat(this.info.lines)]));

@@ -792,7 +800,11 @@ if (_err4 !== undefined) return _err4;

if (columns === false) {
var err = this.__error("Invalid Record Length: expect ".concat(this.state.expectedRecordLength, ", got ").concat(recordLength, " on line ").concat(this.info.lines));
var err = this.__error(new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_PREVIOUS_RECORDS', ['Invalid Record Length:', "expect ".concat(this.state.expectedRecordLength, ","), "got ".concat(recordLength, " on line ").concat(this.info.lines)], {
record: record
}));
if (err !== undefined) return err;
} else {
var _err5 = this.__error("Invalid Record Length: header length is ".concat(columns.length, ", got ").concat(recordLength, " on line ").concat(this.info.lines));
var _err5 = this.__error(new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS', ['Invalid Record Length:', "header length is ".concat(columns.length, ","), "got ".concat(recordLength, " on line ").concat(this.info.lines)], {
record: record
}));

@@ -810,5 +822,5 @@ if (_err5 !== undefined) return _err5;

if (skip_lines_with_empty_values === true) {
if (record.map(function (field) {
return field.trim();
}).join('') === '') {
if (record.every(function (field) {
return field.trim() === '';
})) {
this.__resetRow();

@@ -888,7 +900,8 @@

try {
// record = record.filter(function(field){ return field !== undefined})
var headers = firstLineToHeaders === undefined ? record : firstLineToHeaders.call(null, record);
if (!Array.isArray(headers)) {
return this.__error("Invalid Header Mapping: expect an array, got ".concat(JSON.stringify(headers)));
return this.__error(new CsvError('CSV_INVALID_COLUMN_MAPPING', ['Invalid Column Mapping:', 'expect an array from column function,', "got ".concat(JSON.stringify(headers))], {
headers: headers
}));
}

@@ -1119,3 +1132,3 @@

var skip_lines_with_error = this.options.skip_lines_with_error;
var err = new Error(msg);
var err = typeof msg === 'string' ? new Error(msg) : msg;

@@ -1185,3 +1198,29 @@ if (skip_lines_with_error) {

var CsvError =
/*#__PURE__*/
function (_Error) {
_inherits(CsvError, _Error);
function CsvError(code, message, context) {
var _this2;
_classCallCheck(this, CsvError);
if (Array.isArray(message)) message = message.join(' ');
_this2 = _possibleConstructorReturn(this, _getPrototypeOf(CsvError).call(this, [message]));
Error.captureStackTrace(_assertThisInitialized(_this2), CsvError);
_this2.code = code;
for (var key in context) {
_this2[key] = context[key];
}
return _this2;
}
return CsvError;
}(_wrapNativeSuper(Error));
parse.Parser = Parser;
parse.CsvError = CsvError;
module.exports = parse;

@@ -1188,0 +1227,0 @@

@@ -466,3 +466,11 @@

}else if(relax === false){
const err = this.__error(`Invalid Closing Quote: got "${String.fromCharCode(nextChr)}" at line ${this.info.lines} instead of delimiter, row delimiter, trimable character (if activated) or comment`)
const err = this.__error(
new CsvError('CSV_INVALID_CLOSING_QUOTE', [
'Invalid Closing Quote:',
`got "${String.fromCharCode(nextChr)}"`,
`at line ${this.info.lines}`,
'instead of delimiter, row delimiter, trimable character',
'(if activated) or comment',
], {})
)
if(err !== undefined) return err

@@ -562,3 +570,8 @@ }else{

if(this.state.quoting === true){
const err = this.__error(`Invalid Closing Quote: quote is not closed at line ${this.info.lines}`)
const err = this.__error(
new CsvError('CSV_QUOTE_NOT_CLOSED', [
'Quote Not Closed:',
`the parsing is finished with an opening quote at line ${this.info.lines}`,
])
)
if(err !== undefined) return err

@@ -606,6 +619,22 @@ }else{

if(columns === false){
const err = this.__error(`Invalid Record Length: expect ${this.state.expectedRecordLength}, got ${recordLength} on line ${this.info.lines}`)
const err = this.__error(
new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_PREVIOUS_RECORDS', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
], {
record: record,
})
)
if(err !== undefined) return err
}else{
const err = this.__error(`Invalid Record Length: header length is ${columns.length}, got ${recordLength} on line ${this.info.lines}`)
const err = this.__error(
new CsvError('CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS', [
'Invalid Record Length:',
`header length is ${columns.length},`,
`got ${recordLength} on line ${this.info.lines}`,
], {
record: record,
})
)
if(err !== undefined) return err

@@ -620,3 +649,3 @@ }

if(skip_lines_with_empty_values === true){
if(record.map( (field) => field.trim() ).join('') === ''){
if(record.every( (field) => field.trim() === '' )){
this.__resetRow()

@@ -679,6 +708,13 @@ return

try{
// record = record.filter(function(field){ return field !== undefined})
const headers = firstLineToHeaders === undefined ? record : firstLineToHeaders.call(null, record)
if(!Array.isArray(headers)){
return this.__error(`Invalid Header Mapping: expect an array, got ${JSON.stringify(headers)}`)
return this.__error(
new CsvError('CSV_INVALID_COLUMN_MAPPING', [
'Invalid Column Mapping:',
'expect an array from column function,',
`got ${JSON.stringify(headers)}`
], {
headers: headers,
})
)
}

@@ -853,3 +889,3 @@ const normalizedHeaders = normalizeColumnsArray(headers)

const {skip_lines_with_error} = this.options
const err = new Error(msg)
const err = typeof msg === 'string' ? new Error(msg) : msg
if(skip_lines_with_error){

@@ -907,4 +943,18 @@ this.state.recordHasError = true

class CsvError extends Error {
constructor(code, message, context) {
if(Array.isArray(message)) message = message.join(' ')
super([message])
Error.captureStackTrace(this, CsvError)
this.code = code
for(let key in context){
this[key] = context[key]
}
}
}
parse.Parser = Parser
parse.CsvError = CsvError
module.exports = parse

@@ -911,0 +961,0 @@

7

package.json
{
"version": "4.4.7",
"version": "4.5.0",
"name": "csv-parse",

@@ -84,3 +84,6 @@ "description": "CSV parsing implementing the Node.js `stream.Transform` API",

"./lib/sync.d.ts"
]
],
"dependencies": {
"pad": "^3.2.0"
}
}
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