Created
February 10, 2021 10:29
-
-
Save herzzanu/6da31a84c648513c33fe444ba8c67da9 to your computer and use it in GitHub Desktop.
Parsing file method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mirage/config.js - AAdding a method for parsing the file | |
function parseCSV(file) { | |
// create an array with the file rows as elements | |
let dataRows = file.split(/\\r?\\n|\\r/); | |
// remove the first row which represents the table header | |
dataRows.shift(); | |
let totalAmount = 0; | |
let transfers = dataRows.map((row, index) => { | |
let data = row.split(','); | |
let amount = Number(data[3]); | |
totalAmount += amount; | |
return { | |
amount, | |
bic: data[2], | |
iban: data[1], | |
name: data[0], | |
}; | |
}); | |
return { totalAmount, transfers }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment