Skip to content

Commit

Permalink
Merge pull request #1 from dhirajjadhavrao/duplicate-entries-patch-1
Browse files Browse the repository at this point in the history
Added Row number for Duplicate row entry
  • Loading branch information
dhirajjadhavrao authored May 10, 2021
2 parents be475f1 + 411b909 commit fd811eb
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/csv-file-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,34 @@
* @private
*/
function _checkUniqueFields(file, config) {
if (!file.data.length) {
return;
}

config.headers
.filter(function (header) {
return header.unique
})
.forEach(function (header) {
if (!isValuesUnique(file.data, header.inputName)) {
file.inValidMessages.push(
_isFunction(header.uniqueError)
? header.uniqueError(header.name)
: String(header.name + ' is not unique')
);
}
});
};
if (!file.data.length) {
return;
}

config.headers
.filter(function (header) {
return header.unique;
})
.forEach(function (header) {
if (!isValuesUnique(file.data, header.inputName)) {
var duplicates = [];
file.data.forEach((row, index) => {
var rowPropertyValue = row[header.inputName];
if (duplicates.indexOf(rowPropertyValue) >= 0) {
file.inValidMessages.push(
_isFunction(header.uniqueError)
? header.uniqueError(header.name, index + 1)
: String(index + 1 + ":" + rowPropertyValue + " is not unique")
);
} else {
duplicates.push(rowPropertyValue);
}
});
duplicates = [];
}
});
}


return CSVFileValidator;
})));

0 comments on commit fd811eb

Please sign in to comment.