Skip to content

Detect if a String could be the beginning of a csv

License

Notifications You must be signed in to change notification settings

dotmindlabs/detect-csv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

detect-csv

Windows Mac/Linux
Windows Build status Build Status

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 csv

You add the following options as a second parameter:

  • delimiters Delimiters to detect, defaults to [',', ';', '\t', '|'].
  • newlines Newline characters to detect, defaults to ['\n', '\r'].

Delimiters and newlines don't work with multiple characters, e.g. \r\n.

About

Detect if a String could be the beginning of a csv

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%