Welcome folks today in this blog post we will be
validating whether a given
string is csv or not using
detect-csv library in command line. All the full source code of the application is shown below.
In order to get started you need to install the below
library using the below command
npm i detect-csv
After that you need to make a
index.js file and copy paste the following code
var detect = require('detect-csv')
var csv = detect('a,b,c\n1,2,3')
// prints ',' and '\n'
var isCsv = detect('notacsv')
console.log('This is ' + (csv ? '' : 'not') + ' a csv')
As you can see we are importing the
library at the top and then we are passing the given
string to the method and detecting whether this is a valid csv or not. And also we are finding out the
delimiter of the given string.