csvtoobj
Validate and translate one or more CSVs to JSON. Uses JSON configuration file to define mapping between CSVs and object and supports basic validation of CSV data.
installation
$ npm install --save csvtoobj
configuration
usage
const csvtoobj = ; ;
options
general
- masterCsv: Which CSV will be used for master set of ids.
- requireMatchingId: If true, will not attempt to build objects where ID is not represented in all CSVs
csvFiles
- csvFile: The alias used to reference CSV in other parts of configuration. Example above is masterCsv and slaveCsv.
- name: The filename which can be used to read the file.
- id: The ID that will associate the CSV row with other CSVs in this set.
objects
- objectName: The resulting name of the object in the root of returned object, examples above are recurring and paymentToken.
- objectProperty: The name of a property associated with the object, examples above are recurring.firstName, recurring.lastName.
- alias: Which CSV is associated with this property.
- name: The column in the CSV associated with this property.
- default: If not found or empty, the default value to use instead.
- rules: Validation rules to run against property value.
- lib: Which library to use for validation, see validation section below.
- def: The function name which will be invoked on the lib.
- args: Any args in addition to the already passed property value.
- objectProperty: The name of a property associated with the object, examples above are recurring.firstName, recurring.lastName.
validation
Currently supported libraries:
- validator (see https://www.npmjs.com/package/validator)
- countries (see https://www.npmjs.com/package/country-data)
If failures occur, the details will be appended to the object root under:
object.failures
Failures do not result in objects being removed from list, it is up to the caller to decide what to do if validation failures are present.