-
Notifications
You must be signed in to change notification settings - Fork 0
How to 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,
});For options, when I say boolean, in reality, it can be any true value of javascript. Same for false
You can see examples to help you !
- name:
debug- default:
false- value: boolean:
trueorfalse
This options show the parsed result of your schema (can be useful sometimes)
This options also allow log from the function (example, a mistake)
- name:
separator- default:
,- values: string
.csv stands for "Comma Separated Values", but if you're a rebel, this options is made for you :)
- name:
parse- default:
true- value: boolean:
trueorfalse
This function desactivate the parsing of values: function, int, float, string
With this function all is string
Example
The file :
num1;num2;num3
1;2;3
4;5;6
7;8;9
The code
const schema = {
num1: "",
num2: "",
num3: ""
};
return parseFile(linkFile, schema, {
separator: ";"
});The result
[
{
"num1":"1",
"num2":"2",
"num3":"3",
},
{
"num1":"4",
"num2":"5",
"num3":"6",
},
{
"num1":"7",
"num2":"8",
"num3":"9",
},
]
- name:
lineCallBack- default:
null- value: function (async or not)
It activate the callBack after each line, can be useful if ou want to do a insert in database (for example)
- name:
callBackForce- default:
false- value: boolean:
trueorfalse
This options allow you to force taking the result of the call back even if it's undefined or null
- name:
arrayParse- default:
true- value: boolean:
trueorfalse
This options allow you to disable the parsing in an array.
- name:
overrideFirstLine- default:
false- value:
array of stringorfalse
This options allow you to override the first line.