Update validate.js

This commit is contained in:
Aleksandr Statciuk 2022-04-19 21:57:03 +03:00
parent 9df7946580
commit d3a06b848d

View file

@ -34,6 +34,13 @@ async function main() {
if (/\s+$/.test(csvString)) if (/\s+$/.test(csvString))
return handleError(`Error: empty lines at the end of file not allowed (${filepath})`) return handleError(`Error: empty lines at the end of file not allowed (${filepath})`)
const rows = csvString.split('\r\n')
const headers = rows[0].split(',')
for (let [i, line] of rows.entries()) {
if (line.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/).length !== headers.length)
return handleError(`Error: row ${i + 1} has the wrong number of columns (${filepath})`)
}
const filename = file.getFilename(filepath) const filename = file.getFilename(filepath)
let data = await csv let data = await csv
.fromString(csvString) .fromString(csvString)