
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
csv-file-validator
Advanced tools
Validation of CSV file against user defined schema (returns back object with data and invalid messages)
Validation of CSV file against user defined schema (returns back object with data and invalid messages)
npm install --save csv-file-validator
yarn add csv-file-validator --save
import CSVFileValidator from 'csv-file-validator'
CSVFileValidator(file, config)
.then(csvData => {
csvData.data // Array of objects from file
csvData.inValidData // Array of error messages
})
.catch(err => {})
Please see Demo for more details /demo/index.html
returns the Promise
Type: File
.csv file
Type: Object
Config object should contain:
headers - Type: Array
, row header (title) objects
isHeaderNameOptional - Type: Boolean
, skip headers name if it is empty
isColumnIndexAlphabetic - Type: Boolean
, convert numeric column index to alphabetic letter
parserConfig - Type: Object
, optional, papaparse options.
Default options, which can't be overridden: skipEmptyLines, complete and error
const config = {
headers: [], // required
isHeaderNameOptional: false, // default (optional)
isColumnIndexAlphabetic: false // default (optional)
}
Type: String
name of the row header (title)
Type: String
key name which will be return with value in a column
Type: Boolean
Makes column optional. If true column value will be return
Type: Function
If a header name is omitted or is not the same as in config name headerError function will be called with arguments headerValue, headerName, rowNumber, columnNumber
Type: Boolean
If required is true then a column value will be checked if it is not empty
Type: Function
If value is empty requiredError function will be called with arguments headerName, rowNumber, columnNumber
Type: Boolean
If it is true all header (title) column values will be checked for uniqueness
Type: Function
If one of the header value is not unique uniqueError function will be called with argument headerName, rowNumber
Type: Function
Validate column value. As an argument column value will be passed For e.g.
/**
* @param {String} email
* @return {Boolean}
*/
function(email) {
return isEmailValid(email);
}
Type: Function
If validate returns false validateError function will be called with arguments headerName, rowNumber, columnNumber
Type: Function
Validate column value that depends on other values in other columns. As an argument column value and row will be passed. For e.g.
/**
* @param {String} email
* @param {Array<string>} row
* @return {Boolean}
*/
function(email, row) {
return isEmailDependsOnSomeDataInRow(email, row);
}
Type: Function
If dependentValidate returns false dependentValidateError function will be called with arguments headerName, rowNumber, columnNumber
Type: Boolean
If column contains list of values separated by comma in return object it will be as an array
const config = {
headers: [
{
name: 'First Name',
inputName: 'firstName',
required: true,
requiredError: function (headerName, rowNumber, columnNumber) {
return `${headerName} is required in the ${rowNumber} row / ${columnNumber} column`
}
},
{
name: 'Last Name',
inputName: 'lastName',
required: false
},
{
name: 'Email',
inputName: 'email',
unique: true,
uniqueError: function (headerName) {
return `${headerName} is not unique`
},
validate: function(email) {
return isEmailValid(email)
},
validateError: function (headerName, rowNumber, columnNumber) {
return `${headerName} is not valid in the ${rowNumber} row / ${columnNumber} column`
}
},
{
name: 'Roles',
inputName: 'roles',
isArray: true
},
{
name: 'Country',
inputName: 'country',
optional: true,
dependentValidate: function(email, row) {
return isEmailDependsOnSomeDataInRow(email, row);
}
}
]
}
Any contributions you make are greatly appreciated.
Please read the Contributions Guidelines before submitting a PR.
MIT © Vasyl Stokolosa
FAQs
Validation of CSV file against user defined schema (returns back object with data and invalid messages)
The npm package csv-file-validator receives a total of 15,730 weekly downloads. As such, csv-file-validator popularity was classified as popular.
We found that csv-file-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.