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

csv-to-js-parser

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-to-js-parser - npm Package Compare versions

Comparing version 2.3.3 to 2.3.4

92

app.js

@@ -38,3 +38,3 @@ /*

let description;
let delimeter;
let delimiter;
if (param1 || param2)

@@ -46,3 +46,3 @@ {

{
delimeter = param1;
delimiter = param1;
}

@@ -58,3 +58,3 @@ else

{
delimeter = param2;
delimiter = param2;
}

@@ -68,5 +68,5 @@ else

if (!delimeter) delimeter = ',';
if (!delimiter) delimiter = ',';
const dataSplited = splitTiaQuotes(data, delimeter);
const dataSplited = splitTiaQuotes(data, delimiter);
let header = dataSplited[0];

@@ -93,3 +93,3 @@ data = dataSplited[1];

let index = header.indexOf(key, 0);
if (index === -1) throw new Error('Cannnot find selected fields in the header');
if (index === -1) throw new Error('Can\'t find selected fields in the header');
if (Number(description[key].group) > 0)

@@ -181,3 +181,3 @@ {

if (Object.keys(arraysIndexes).length) //If we have not group columns then we need create arrays in every object. Else we need put equal rows to separate objects.
if (Object.keys(arraysIndexes).length) //If we don't have group columns then we need create arrays in every object. Else we need put equal rows to separate objects.
{

@@ -247,3 +247,3 @@ for (let i = 0; i < data.length; i++)

{
throw new Error('Cannont convert boolean value');
throw new Error('Can\'t convert boolean value');
}

@@ -255,4 +255,4 @@ }

}
//Split by delimeter, taking into account double quotes according to rfc4180
function splitTiaQuotes(data, delimeter)
//Split by delimiter, taking into account double quotes according to rfc4180
function splitTiaQuotes(data, delimiter)
{

@@ -268,6 +268,6 @@ const dataArray = [];

let qPlaceClosed = -1;
let hasNotSpaceSimbolAfterClosingQuotes;
let hasNotSpaceSymbolAfterClosingQuotes;
for (;;)
{
if (dPlace >= 0 && dPlace <= dOrnPlace) dPlace = data.indexOf(delimeter, dataIndex);
if (dPlace >= 0 && dPlace <= dOrnPlace) dPlace = data.indexOf(delimiter, dataIndex);
if (rnPlace >= 0 && rnPlace <= dOrnPlace) rnPlace = data.indexOf('\n', dataIndex);

@@ -290,16 +290,16 @@ set_dOrnPlace();

{
while (data[qPlaceClosed + 1] === '"') //qPlaceClosed refer to escape simbol of "
while (data[qPlaceClosed + 1] === '"') //qPlaceClosed refer to escape symbol of "
{
qPlaceClosed = data.indexOf('"', qPlaceClosed + 2);
}
hasNotSpaceSimbolAfterClosingQuotes = false;
for (let i = qPlaceClosed + 1; i < data.length; i++) //After closing quotes and before delimeter we have not space simbols
hasNotSpaceSymbolAfterClosingQuotes = false;
for (let i = qPlaceClosed + 1; i < data.length; i++) //After closing quotes and before delimiter we don't have space symbols
{
if (data[i] !== ' ')
{
hasNotSpaceSimbolAfterClosingQuotes = true;
hasNotSpaceSymbolAfterClosingQuotes = true;
break;
}
}
if (hasNotSpaceSimbolAfterClosingQuotes)
if (hasNotSpaceSymbolAfterClosingQuotes)
{

@@ -347,7 +347,7 @@ rowArray.push(data.slice(dataIndex, data.length));

}
if (fieldStartsFromQuote) //filed start from quote
if (fieldStartsFromQuote) //field starts from quote
{
for (;;)
{
if (data[qPlaceClosed + 1] === '"') //qPlaceClosed refer to escape simbol of "
if (data[qPlaceClosed + 1] === '"') //qPlaceClosed refer to escape symbol of "
{

@@ -358,5 +358,5 @@ qPlaceClosed = data.indexOf('"', qPlaceClosed + 2);

{
if (dOrnPlace < qPlaceClosed) //dOrnPlace refer to delimeter into escaped filed, for example ""aa, aa
if (dOrnPlace < qPlaceClosed) //dOrnPlace refer to delimiter into escaped field, for example ""aa, aa
{
if (dPlace < qPlaceClosed) dPlace = data.indexOf(delimeter, qPlaceClosed + 1);
if (dPlace < qPlaceClosed) dPlace = data.indexOf(delimiter, qPlaceClosed + 1);
if (rnPlace < qPlaceClosed) rnPlace = data.indexOf('\n', qPlaceClosed + 1);

@@ -368,4 +368,4 @@ set_dOrnPlace();

}
hasNotSpaceSimbolAfterClosingQuotes = false;
for (let i = qPlaceClosed + 1; i < dOrnPlace; i++) //After closing quotes and before delimeter we have not space simbols
hasNotSpaceSymbolAfterClosingQuotes = false;
for (let i = qPlaceClosed + 1; i < dOrnPlace; i++) //After closing quotes and before delimiter we don't have space symbols
{

@@ -375,7 +375,7 @@ let s = data[i];

{
hasNotSpaceSimbolAfterClosingQuotes = true;
hasNotSpaceSymbolAfterClosingQuotes = true;
break;
}
}
if (hasNotSpaceSimbolAfterClosingQuotes)
if (hasNotSpaceSymbolAfterClosingQuotes)
{

@@ -391,3 +391,3 @@ rowArray.push(data.slice(dataIndex, dOrnPlace));

}
else //filed has quote, but not start from quote
else //field has quotes but does not start from quote
{

@@ -399,3 +399,3 @@ addFieldWithNoQuotes();

}
else //filed has not quotes
else //no quotes in the field
{

@@ -468,18 +468,18 @@ addFieldWithNoQuotes();

module.exports.objToCsv = function(obj, delimeter, rowDelimeter)
module.exports.objToCsv = function(obj, delimiter, rowDelimiter)
{
if (!Array.isArray(obj)) throw new Error('Object is not array');
if (!Array.isArray(obj)) throw new Error('Object is not an array');
if (!obj[0]) throw new Error('Object error');
if (!delimeter) delimeter = ',';
if (!rowDelimeter)
if (!delimiter) delimiter = ',';
if (!rowDelimiter)
{
rowDelimeter = '\n';
rowDelimiter = '\n';
}
else if (rowDelimeter.toLowerCase() === 'lf')
else if (rowDelimiter.toLowerCase() === 'lf')
{
rowDelimeter = '\n';
rowDelimiter = '\n';
}
else if (rowDelimeter.toLowerCase() === 'crlf')
else if (rowDelimiter.toLowerCase() === 'crlf')
{
rowDelimeter = '\r\n';
rowDelimiter = '\r\n';
}

@@ -493,6 +493,6 @@ let out = '';

out += needQuotesCheck(keys[i].toString());
if (i !== keys.length - 1) out += delimeter;
if (i !== keys.length - 1) out += delimiter;
isConstant[i] = !Array.isArray(obj[0][keys[i]]);
}
out += rowDelimeter;
out += rowDelimiter;
//Body

@@ -511,3 +511,3 @@ for (let elem of obj)

}
//Fill rows
//Filling rows
if (maxArrayLength) //have array properties

@@ -529,5 +529,5 @@ {

}
if (j !== keys.length - 1) out += delimeter;
if (j !== keys.length - 1) out += delimiter;
}
out += rowDelimeter;
out += rowDelimiter;
}

@@ -541,5 +541,5 @@ }

if (val !== null) out += needQuotesCheck(val.toString());
if (i !== keys.length - 1) out += delimeter;
if (i !== keys.length - 1) out += delimiter;
}
out += rowDelimeter;
out += rowDelimiter;
}

@@ -553,3 +553,3 @@ }

{
if (val.indexOf(delimeter) === -1 && val.indexOf('\n') === -1) return val;
if (val.indexOf(delimiter) === -1 && val.indexOf('\n') === -1) return val;
}

@@ -567,3 +567,3 @@ else

if (!newArrayKeys) newArrayKeys = arrayKeys;
if (newArrayKeys.length !== arrayKeys.length) throw new Error('Parameters arrayKeys and newArrayKeys should have same length');
if (newArrayKeys.length !== arrayKeys.length) throw new Error('Parameters "arrayKeys" and "newArrayKeys" should have same length');
if (!Array.isArray(obj)) throw new Error('Object is not array');

@@ -603,3 +603,3 @@ if (!obj[0]) throw new Error('Object error');

if (!newArrayKeys) newArrayKeys = arrayKeys;
if (newArrayKeys.length !== arrayKeys.length) throw new Error('Parameters arrayKeys and newArrayKeys should have same length');
if (newArrayKeys.length !== arrayKeys.length) throw new Error('Parameters "arrayKeys" and "newArrayKeys" should have same length');
if (!Array.isArray(obj)) throw new Error('Object is not array');

@@ -606,0 +606,0 @@ if (!obj[0]) throw new Error('Object error');

{
"name": "csv-to-js-parser",
"version": "2.3.3",
"version": "2.3.4",
"description": "Converting csv data into array of JavaScript objects. This module can group input data.",

@@ -5,0 +5,0 @@ "main": "app.js",

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