1.0.8 • Published 1 year ago

csv-alidator v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

csv-alidator

NPM package written in JavaScript to quickly validate a csv file based on RCF 4180 directives and find wrong records among millions of lines and many columns.

Installation

You can install this package via npm.

npm i csv-alidator

Package check

Just to check the success of the installation, also returns basic package information.

/**
 * No parameters.
 */

const csvalidator = require('csv-alidator');
console.log(csvalidator.itWorks());

#output : { json } > {
#    "itWorks": "Yes, it works!",
#    "package": "csv-alidator",
#    "version": "1.0.3"
#}

Usage

Validations

booleanValidation

Validates a CSV file giving back true or false.

ParamTypeDescription
csvFilestringPath to local CSV file
csvDelimiterstringThe CSV delimiter character, not mandatory. Default value = ','
ignoreEmptyRowsboolNon-mandatory parameter to handle the blank line at the end of the file
const csvalidator = require('csv-alidator');
console.log(csvalidator.booleanValidation('path-to-local-csv-file'));

#output : { bool } > true | false

jsonValidation

Validates a CSV file giving back json with information about: execution result and time, CSV file name, array containing lines numbers with error. Also very useful for quickly finding the wrong records among millions of lines.

ParamTypeDescription
csvFilestringPath to local CSV file
csvDelimiterstringThe CSV delimiter character, not mandatory. Default value = ','
ignoreEmptyRowsboolNon-mandatory parameter to handle the blank line at the end of the file
const csvalidator = require('csv-alidator');
console.log(csvalidator.jsonValidation('path-to-local-csv-file'));

#output { json } > successful validation: {
#    "csvFile": "path-to-local-csv-file",
#    "executiontime": "5496ms.",
#    "rowsCount": 1000001,
#    "columns": 9,
#    "badRowsLines": [],
#    "result": true,
#    "message": ""
#}

#output { json } > failed validation: {
#    "csvFile": "path-to-local-csv-file",
#    "executiontime": "4817ms.",
#    "rowsCount": 1000001,
#    "columns": 9,
#    "badRowsLines": [
#        394579,
#        941245
#    ],
#    "result": false,
#    "message": ""
#}

#output { json } > failed no such file: {
#    "csvFile": "path-to-local-csv-file",
#    "executiontime": "1ms.",
#    "rowsCount": null,
#    "columns": null,
#    "badRowsLines": null,
#    "result": false,
#    "message": "ENOENT: no such file or directory, open 'path-to-csv-file'"
#}

Performance considerations

csv-alidator is designed and tested to quickly validate even large csv files with millions of rows and many columns.

Comma-Separated Values (CSV)

RCF 4180 directives

License

MIT

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago