diff --git a/docs/docs.html b/docs/docs.html
index 68f1132..bf2f0df 100644
--- a/docs/docs.html
+++ b/docs/docs.html
@@ -355,7 +355,8 @@ var csv = Papa.unparse({
fastMode: undefined,
beforeFirstChunk: undefined,
withCredentials: undefined,
- transform: undefined
+ transform: undefined,
+ delimitersToGuess: [',', '\t', '|', ';', String.fromCharCode(30), String.fromCharCode(31)]
}
@@ -375,7 +376,7 @@ var csv = Papa.unparse({
delimiter
- The delimiting character. Leave blank to auto-detect from a list of most common delimiters. It can be a string or a function. If string, it must be one of length 1. If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in Papa.BAD_DELIMITERS.
+ The delimiting character. Leave blank to auto-detect from a list of most common delimiters, or any values passed in through delimitersToGuess . It can be a string or a function. If string, it must be one of length 1. If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in Papa.BAD_DELIMITERS.
|
@@ -548,6 +549,14 @@ var csv = Papa.unparse({
A function to apply on each value. The function receives the value as its first argument and the column number as its second argument. The return value of the function will replace the value it received. The transform function is applied before dynamicTyping.
+
+
+ delimitersToGuess
+ |
+
+ An array of delimiters to guess from if the delimiter option is not set.
+ |
+
diff --git a/papaparse.js b/papaparse.js
index 059ccbb..60fa700 100755
--- a/papaparse.js
+++ b/papaparse.js
@@ -1024,7 +1024,7 @@
_delimiterError = false;
if (!_config.delimiter)
{
- var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines, _config.comments);
+ var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines, _config.comments, _config.delimitersToGuess);
if (delimGuess.successful)
_config.delimiter = delimGuess.bestDelimiter;
else
@@ -1208,14 +1208,15 @@
return _results;
}
- function guessDelimiter(input, newline, skipEmptyLines, comments)
+ function guessDelimiter(input, newline, skipEmptyLines, comments, delimitersToGuess)
{
- var delimChoices = [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP];
var bestDelim, bestDelta, fieldCountPrevRow;
- for (var i = 0; i < delimChoices.length; i++)
+ delimitersToGuess = delimitersToGuess || [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP];
+
+ for (var i = 0; i < delimitersToGuess.length; i++)
{
- var delim = delimChoices[i];
+ var delim = delimitersToGuess[i];
var delta = 0, avgFieldCount = 0, emptyLinesCount = 0;
fieldCountPrevRow = undefined;
diff --git a/tests/test-cases.js b/tests/test-cases.js
index deb2e65..b002b39 100644
--- a/tests/test-cases.js
+++ b/tests/test-cases.js
@@ -2110,7 +2110,6 @@ var CUSTOM_TESTS = [
});
}
}
-
];
describe('Custom Tests', function() {
@@ -2127,3 +2126,40 @@ describe('Custom Tests', function() {
generateTest(CUSTOM_TESTS[i]);
}
});
+
+
+var DELIMITERS_TO_GUESS_TESTS = [
+ {
+ description: "Should correctly guess custom delimiter when passed delimiters to guess.",
+ expected: "~",
+ run: function(callback) {
+ var results = Papa.parse('"A"~"B"~"C"~"D"', {
+ delimitersToGuess: ['~', '@', '%']
+ });
+ callback(results.meta.delimiter);
+ }
+ },
+ {
+ description: "Should still correctly guess default delimiters when delimiters to guess are not given.",
+ expected: ",",
+ run: function(callback) {
+ var results = Papa.parse('"A","B","C","D"');
+ callback(results.meta.delimiter);
+ }
+ }
+];
+
+describe('Delimiters to Guess Tests', function() {
+ function generateTest(test) {
+ (test.disabled ? it.skip : it)(test.description, function(done) {
+ test.run(function(actual) {
+ assert.deepEqual(JSON.stringify(actual), JSON.stringify(test.expected));
+ done();
+ });
+ });
+ }
+
+ for (var i = 0; i < DELIMITERS_TO_GUESS_TESTS.length; i++) {
+ generateTest(DELIMITERS_TO_GUESS_TESTS[i]);
+ }
+});