package
Detect if a chunk of a string is a csv
npm install detect-csvGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Detect if a chunk in the beginning of a CSV (in the sense of character seperated values)
is valid and determine the delimiter character. Install with npm install detect-csv
Right now it only parses the first line and counts characters. So the rest of the CSV might be invalid. Also I recommend checking for json/ndjson first, since it's the more strict format.
var detect = require('detect-csv')
var csv = detect('a,b,c\n1,2,3')
console.log(csv.delimiter)
console.log(csv.newline)
// prints ',' and '\n'
var isCsv = detect('notacsv')
console.log('This is ' + (isCsv ? '' : 'not') + ' a csv')
// prints: This is not a csvYou add the following options as a second parameter:
[',', ';', '\t', '|']Delimiters and newlines don't work with multiple characters, e.g. \r\n.