npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

csv-file-validator

v2.2.0

Published

Validation of CSV file against user defined schema (returns back object with data and invalid messages)

Downloads

130,737

Readme

CSV File Validator Twitter URL

MIT Licence codecov Build Status Known Vulnerabilities npm version

Validation of CSV file against user defined schema (returns back object with data and invalid messages)

Getting csv-file-validator

npm

npm install --save csv-file-validator

yarn

yarn add csv-file-validator --save

Example

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

API

CSVFileValidator(file, config)

returns the Promise

file

Type: File

.csv file

config

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)
}

name

Type: String name of the row header (title)

inputName

Type: String key name which will be return with value in a column

optional

Type: Boolean

Makes column optional. If true column value will be return

headerError

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

required

Type: Boolean

If required is true then a column value will be checked if it is not empty

requiredError

Type: Function

If value is empty requiredError function will be called with arguments headerName, rowNumber, columnNumber

unique

Type: Boolean

If it is true all header (title) column values will be checked for uniqueness

uniqueError

Type: Function

If one of the header value is not unique uniqueError function will be called with argument headerName, rowNumber

validate

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);
}

validateError

Type: Function

If validate returns false validateError function will be called with arguments headerName, rowNumber, columnNumber

dependentValidate

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);
}

dependentValidateError

Type: Function

If dependentValidate returns false dependentValidateError function will be called with arguments headerName, rowNumber, columnNumber

isArray

Type: Boolean

If column contains list of values separated by comma in return object it will be as an array

Config example

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);
            }
        }
    ]
}

Contributing

Any contributions you make are greatly appreciated.

Please read the Contributions Guidelines before submitting a PR.

License

MIT © Vasyl Stokolosa