csv-string
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -44,21 +44,17 @@ 'use strict'; | ||
exports.detect = function (input) | ||
exports.detect = function detect (input) | ||
{ | ||
var separators = [{c: 0, v: ','}, {c: 0, v: ';'}, {c: 0, v: '|'}, {c: 0, v: '\t'}, {c: 0, v: ':'}, {c: 0, v: null}]; | ||
separators.forEach(function (item, indice) { | ||
item.c += input.split(item.v).length; | ||
var separators = [',', ';', '|', '\t']; | ||
var min = 99999999; | ||
var idx = separators.map(function (separator, index) { | ||
return input.indexOf(separator); | ||
}).reduce(function (prev, cur, index) { | ||
if (cur !== -1 && cur < min) { | ||
return cur; | ||
} | ||
); | ||
var max = 0; | ||
var separator = separators.reduce(function (prev, cur) { | ||
if (cur.c >= max) { | ||
max = cur.c; | ||
return cur.v; | ||
} | ||
else { | ||
return prev; | ||
} | ||
}, null | ||
); | ||
return separator; | ||
else { | ||
return prev; | ||
} | ||
}); | ||
return input[idx] || ','; | ||
} | ||
@@ -65,0 +61,0 @@ |
{ | ||
"name": "csv-string", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17529
388