From 8143db9f70d9bee3854a8f1d5aa729a885e78703 Mon Sep 17 00:00:00 2001 From: AkvelonAccount Date: Thu, 8 Oct 2020 11:10:43 +0300 Subject: [PATCH] Added option quoteDataWithSpaces (default - true) to unparse config. If quoteDataWithSpaces set to false, unparse result doesn't quote data with spaces in the start or in the end. --- papaparse.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/papaparse.js b/papaparse.js index e1825d1..ae290c5 100755 --- a/papaparse.js +++ b/papaparse.js @@ -285,6 +285,9 @@ License: MIT /** whether to prevent outputting cells that can be parsed as formulae by spreadsheet software (Excel and LibreOffice) */ var _escapeFormulae = false; + /** whether to surround every datum that has spaces in the start or in the end with quotes */ + var _quoteDataWithSpaces = true; + unpackConfig(); var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g'); @@ -367,6 +370,9 @@ License: MIT if (typeof _config.escapeFormulae === 'boolean') _escapeFormulae = _config.escapeFormulae; + + if (typeof _config.quoteDataWithSpaces === 'boolean') + _quoteDataWithSpaces = _config.quoteDataWithSpaces; } @@ -464,8 +470,8 @@ License: MIT || (Array.isArray(_quotes) && _quotes[col]) || hasAny(escapedQuoteStr, Papa.BAD_DELIMITERS) || escapedQuoteStr.indexOf(_delimiter) > -1 - || escapedQuoteStr.charAt(0) === ' ' - || escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === ' '; + || (_quoteDataWithSpaces && escapedQuoteStr.charAt(0) === ' ') + || (_quoteDataWithSpaces && escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === ' '); return needsQuotes ? _quoteChar + escapedQuoteStr + _quoteChar : escapedQuoteStr; }