Skip to content

Commit

Permalink
Upgrade papaparse to 5.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cavenel committed Dec 4, 2023
1 parent cbe2003 commit 2822b50
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 87 deletions.
4 changes: 2 additions & 2 deletions tissuumaps/static/vendor/PapaParse-5.3.0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "papaparse",
"version": "5.2.0",
"version": "5.3.2",
"description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.",
"keywords": [
"csv",
Expand Down Expand Up @@ -43,7 +43,7 @@
"grunt": "^1.0.2",
"grunt-contrib-uglify": "^3.3.0",
"mocha": "^5.2.0",
"mocha-headless-chrome": "^2.0.1",
"mocha-headless-chrome": "^4.0.0",
"open": "7.0.0",
"serve-static": "^1.7.1"
},
Expand Down
110 changes: 27 additions & 83 deletions tissuumaps/static/vendor/PapaParse-5.3.0/papaparse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @license
Papa Parse
v5.2.0
v5.3.2
https://github.com/mholt/PapaParse
License: MIT
*/
Expand Down Expand Up @@ -297,7 +297,7 @@ License: MIT
if (!_input.length || Array.isArray(_input[0]))
return serialize(null, _input, _skipEmptyLines);
else if (typeof _input[0] === 'object')
return serialize(_columns || objectKeys(_input[0]), _input, _skipEmptyLines);
return serialize(_columns || Object.keys(_input[0]), _input, _skipEmptyLines);
}
else if (typeof _input === 'object')
{
Expand All @@ -307,12 +307,14 @@ License: MIT
if (Array.isArray(_input.data))
{
if (!_input.fields)
_input.fields = _input.meta && _input.meta.fields;
_input.fields = _input.meta && _input.meta.fields || _columns;

if (!_input.fields)
_input.fields = Array.isArray(_input.data[0])
? _input.fields
: objectKeys(_input.data[0]);
: typeof _input.data[0] === 'object'
? Object.keys(_input.data[0])
: [];

if (!(Array.isArray(_input.data[0])) && typeof _input.data[0] !== 'object')
_input.data = [_input.data]; // handles input like [1,2,3] or ['asdf']
Expand Down Expand Up @@ -365,20 +367,9 @@ License: MIT
_escapedQuote = _config.escapeChar + _quoteChar;
}

if (typeof _config.escapeFormulae === 'boolean')
_escapeFormulae = _config.escapeFormulae;
}


/** Turns an object's keys into an array */
function objectKeys(obj)
{
if (typeof obj !== 'object')
return [];
var keys = [];
for (var key in obj)
keys.push(key);
return keys;
if (typeof _config.escapeFormulae === 'boolean' || _config.escapeFormulae instanceof RegExp) {
_escapeFormulae = _config.escapeFormulae instanceof RegExp ? _config.escapeFormulae : /^[=+\-@\t\r].*$/;
}
}

/** The double for loop that iterates the data and writes out a CSV string including header row */
Expand Down Expand Up @@ -453,13 +444,17 @@ License: MIT
if (str.constructor === Date)
return JSON.stringify(str).slice(1, 25);

if (_escapeFormulae === true && typeof str === "string" && (str.match(/^[=+\-@].*$/) !== null)) {
var needsQuotes = false;

if (_escapeFormulae && typeof str === "string" && _escapeFormulae.test(str)) {
str = "'" + str;
needsQuotes = true;
}

var escapedQuoteStr = str.toString().replace(quoteCharRegex, _escapedQuote);

var needsQuotes = (typeof _quotes === 'boolean' && _quotes)
needsQuotes = needsQuotes
|| _quotes === true
|| (typeof _quotes === 'function' && _quotes(str, col))
|| (Array.isArray(_quotes) && _quotes[col])
|| hasAny(escapedQuoteStr, Papa.BAD_DELIMITERS)
Expand Down Expand Up @@ -1016,8 +1011,8 @@ License: MIT
// One goal is to minimize the use of regular expressions...
var MAX_FLOAT = Math.pow(2, 53);
var MIN_FLOAT = -MAX_FLOAT;
var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)(e[-+]?\d+)?\s*$/;
var ISO_DATE = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/;
var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/;
var ISO_DATE = /^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$/;
var self = this;
var _stepCounter = 0; // Number of times step was called (number of rows parsed)
var _rowCounter = 0; // Number of rows that have been parsed so far
Expand Down Expand Up @@ -1168,9 +1163,9 @@ License: MIT

if (_config.skipEmptyLines)
{
for (var i = 0; i < _results.data.length; i++)
if (testEmptyLine(_results.data[i]))
_results.data.splice(i--, 1);
_results.data = _results.data.filter(function(d) {
return !testEmptyLine(d);
});
}

if (needsHeaderRow())
Expand Down Expand Up @@ -1408,8 +1403,7 @@ License: MIT
var preview = config.preview;
var fastMode = config.fastMode;
var quoteChar;
/** Allows for no quoteChar by setting quoteChar to undefined in config */
if (config.quoteChar === undefined) {
if (config.quoteChar === undefined || config.quoteChar === null) {
quoteChar = '"';
} else {
quoteChar = config.quoteChar;
Expand Down Expand Up @@ -1564,7 +1558,7 @@ License: MIT
var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);

// Closing quote followed by delimiter or 'unnecessary spaces + delimiter'
if (input[quoteSearch + 1 + spacesBetweenQuoteAndDelimiter] === delim)
if (input.substr(quoteSearch + 1 + spacesBetweenQuoteAndDelimiter, delimLen) === delim)
{
row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
cursor = quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen;
Expand Down Expand Up @@ -1634,27 +1628,11 @@ License: MIT
// Next delimiter comes before next newline, so we've reached end of field
if (nextDelim !== -1 && (nextDelim < nextNewline || nextNewline === -1))
{
// we check, if we have quotes, because delimiter char may be part of field enclosed in quotes
if (quoteSearch > nextDelim) {
// we have quotes, so we try to find the next delimiter not enclosed in quotes and also next starting quote char
var nextDelimObj = getNextUnquotedDelimiter(nextDelim, quoteSearch, nextNewline);

// if we have next delimiter char which is not enclosed in quotes
if (nextDelimObj && typeof nextDelimObj.nextDelim !== 'undefined') {
nextDelim = nextDelimObj.nextDelim;
quoteSearch = nextDelimObj.quoteSearch;
row.push(input.substring(cursor, nextDelim));
cursor = nextDelim + delimLen;
// we look for next delimiter char
nextDelim = input.indexOf(delim, cursor);
continue;
}
} else {
row.push(input.substring(cursor, nextDelim));
cursor = nextDelim + delimLen;
nextDelim = input.indexOf(delim, cursor);
continue;
}
row.push(input.substring(cursor, nextDelim));
cursor = nextDelim + delimLen;
// we look for next delimiter char
nextDelim = input.indexOf(delim, cursor);
continue;
}

// End of row
Expand Down Expand Up @@ -1759,40 +1737,6 @@ License: MIT
data = [];
errors = [];
}

/** Gets the delimiter character, which is not inside the quoted field */
function getNextUnquotedDelimiter(nextDelim, quoteSearch, newLine) {
var result = {
nextDelim: undefined,
quoteSearch: undefined
};
// get the next closing quote character
var nextQuoteSearch = input.indexOf(quoteChar, quoteSearch + 1);

// if next delimiter is part of a field enclosed in quotes
if (nextDelim > quoteSearch && nextDelim < nextQuoteSearch && (nextQuoteSearch < newLine || newLine === -1)) {
// get the next delimiter character after this one
var nextNextDelim = input.indexOf(delim, nextQuoteSearch);

// if there is no next delimiter, return default result
if (nextNextDelim === -1) {
return result;
}
// find the next opening quote char position
if (nextNextDelim > nextQuoteSearch) {
nextQuoteSearch = input.indexOf(quoteChar, nextQuoteSearch + 1);
}
// try to get the next delimiter position
result = getNextUnquotedDelimiter(nextNextDelim, nextQuoteSearch, newLine);
} else {
result = {
nextDelim: nextDelim,
quoteSearch: quoteSearch
};
}

return result;
}
};

/** Sets the abort flag */
Expand Down
Loading

0 comments on commit 2822b50

Please sign in to comment.