Skip to content

Instantly share code, notes, and snippets.

@herzzanu
Created February 10, 2021 10:29
Show Gist options
  • Save herzzanu/6da31a84c648513c33fe444ba8c67da9 to your computer and use it in GitHub Desktop.
Save herzzanu/6da31a84c648513c33fe444ba8c67da9 to your computer and use it in GitHub Desktop.
Parsing file method
// 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