Skip to content

Commit

Permalink
class CsvToJson
Browse files Browse the repository at this point in the history
- Add private #index to hold indexHeader value, default 0
- Update indexHeader()
- Update getIndexHeader()
  • Loading branch information
J-Siu committed Jul 18, 2023
1 parent d747586 commit 2775862
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/csvToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const defaultFieldDelimiter = ";";

class CsvToJson {

#index = 0

formatValueByType(active) {
this.printValueFormatByType = active;
return this;
Expand All @@ -24,11 +26,11 @@ class CsvToJson {
return this;
}

indexHeader(indexHeader) {
if(isNaN(indexHeader)){
indexHeader(index) {
if(isNaN(index)){
throw new Error('The index Header must be a Number!');
}
this.indexHeader = indexHeader;
this.#index = index;
return this;
}

Expand Down Expand Up @@ -100,10 +102,7 @@ class CsvToJson {
}

getIndexHeader(){
if(this.indexHeader !== null && !isNaN(this.indexHeader)){
return this.indexHeader;
}
return 0;
return this.#index;
}

buildJsonResult(headers, currentLine) {
Expand Down

0 comments on commit 2775862

Please sign in to comment.