Welcome folks today in this blog post we will be detecting
or 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.
Get Started
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
index.js
1 2 3 4 5 6 7 8 9 10 |
var detect = require('detect-csv') var csv = detect('a,b,c\n1,2,3') console.log(csv.delimiter) console.log("ds"+csv.newline) // 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.