Skip to content

How to options

n4n5 edited this page Jul 11, 2021 · 9 revisions

How to use csv-to-custom-json options

Options

To use options, you need to add a third paramters which is an object with options.

Example :

const parsedFile = await parseFile("myfile.csv", schema, {
    debug: true,
});

Informations for tests

  • For options, when it's writed boolean, in reality, it can be any true value of javascript. Same for false.

  • command to run test

Test can be run with options :

npm -s run test -- -n test/callBack_force.test.js callBack_force.test.js

Legend :

  • -s is to silent npm
  • -- is used to pass the -n parameters to the test.js file
  • -n is used to allow only useful log
  • test/callBack_force.test.js and callBack_force.test.js are here to demonstrate that you can omit the test/ in the string

Debug

  • name: debug
  • default: false
  • value: boolean: true or false

This options show the parsed result of your schema (can be useful sometimes)

This options also allow log from the function (example, a mistake)

Test
npm -s run test test/debug.test.js

Separator

  • name: separator
  • default: ,
  • values: string

.csv stands for "Comma Separated Values", but if you're a rebel, this options is made for you :)

Test
npm -s run test test/custom_separator.test.js

Parse

  • name: parse
  • default: true
  • value: boolean: true or false

This function desactivate the parsing of values: function, int, float, string

With this function all is string

Test
npm -s run test test/stop_parse_value.test.js

Line Call Back

  • name: lineCallBack
  • default: null
  • value: function (async or not)

It activates the callBack after each line, can be useful if ou want to do a insert in database (for example)

Test
npm -s run test test/line_callBack.test.js

Call Back Force

  • name: callBackForce
  • default: false
  • value: boolean: true or false

This options allow you to force taking the result of the callBackLine even if it's undefined or null

Test
npm -s run test test/callBack_force.test.js
npm -s run test test/callBack_force_2.test.js

Array Parse

  • name: arrayParse
  • default: true
  • value: boolean: true or false

This options allow you to disable the parsing in an array.

Test
npm -s run test test/array_parse.test.js

Override First Line

  • name: overrideFirstLine
  • default: false
  • value: array of string or false

This options allow you to override the first line.

Test
npm -s run test test/override_first_line.test.js

Private separator

  • name: privateSeparator
  • default: ...
  • value: string

This options allow you to change the internal separator of the script. It can be useful if values contain . in their names

Test
npm -s run test test/private_separator.test.js test/private_separator_2.test.js

Avoid void line

  • name: avoidVoidLine
  • default: false
  • value: boolean

This options allow you to not parse void line

Test
npm -s run test test/avoidVoidLine.test.js test/avoidVoidLine2.test.js test/avoidVoidLine3.test.js