Last active
June 20, 2016 17:05
-
-
Save Zodiase/3f91c632db6506b74abd34f1c66ecb1c to your computer and use it in GitHub Desktop.
Parse the text data from Chase Checking or Saving activities and save as a CSV file.
This file contains 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
'use strict'; | |
const nodePath = process.argv[0], | |
exePath = process.argv[1], | |
inputPath = process.argv[2], | |
fs = require('fs'); | |
if (typeof inputPath === 'undefined') { | |
throw new Error('Need to specify input file path.'); | |
} | |
const outputPath = `${inputPath}.out.csv`; | |
const inputData = fs.readFileSync(inputPath, 'utf-8'); | |
let inputDataCopy = inputData; | |
let parsing = null; | |
const regExp = /^\s*?([0-9\/]+?) \t([^\s][^\t$]*?)\t([^\s][^\t$]*?)\t([.,\-$0-9]*?) \t([.,\-$0-9]*?) \t([.,\-$0-9]*?)\s*?$/m; | |
const resultRecords = []; | |
while (parsing = inputDataCopy.match(regExp)) { | |
resultRecords.push([ | |
parsing[1], // Date | |
parsing[2], // Transaction Type | |
parsing[3], // Description | |
parsing[4], // Debit | |
parsing[5], // Credit | |
parsing[6] // Balance | |
]); | |
inputDataCopy = inputDataCopy.substr(parsing[0].length); | |
} | |
const outputData = resultRecords.map((item) => item.map((value) => `"${value}"`).join(',')).join('\n'); | |
fs.writeFileSync(outputPath, outputData, 'utf-8'); |
This file contains 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
01/01/2016 ACH Debit Sample Description $123.45 $987.66 | |
01/01/2016 Account Transfer Sample Description $123.45 $1,111.11 | |
01/01/2016 ACH Credit Sample Description $1,234.56 $1,234.56 |
This file contains 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
01/01/2016 | ACH Debit | Sample Description | $123.45 | $987.66 | ||
---|---|---|---|---|---|---|
01/01/2016 | Account Transfer | Sample Description | $123.45 | $1,111.11 | ||
01/01/2016 | ACH Credit | Sample Description | $1,234.56 | $1,234.56 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment