ratchapong

Untitled

Sep 10th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. const fs = require('fs');
  2. const parse = require('csv-parse');
  3. const parser = parse({
  4. delimiter: ',',
  5. });
  6. const ACTIONS = {
  7. DEPOSIT: 'Deposit',
  8. TRANSFER: 'Transfer',
  9. RECEIVE: 'Receive',
  10. PAYMENT: 'Payment',
  11. SWIPE: 'Swipe',
  12. };
  13. parse(fs.readFileSync('./ss.csv').toString(), {
  14. comment: '#',
  15. }, function (err, output) {
  16. const newLines = [];
  17. output.forEach(o => {
  18. const [dirtyDate, outAmount, inAmount, , note] = o;
  19. const [dd, mm, yy] = dirtyDate.trim().split(' ')[0].split('/');
  20. const cleanDate = [ Number(yy), String(Number(mm)).padStart(2,0), String(Number(dd)).padStart(2,0)].join('-');
  21. newLines.push(['Others', cleanDate, Number(outAmount.replace(/,/g, '')), Number(inAmount.replace(/,/g, '')), 'Note'].join(','));
  22. const newNote = {
  23. action: null,
  24. };
  25.  
  26. });
  27. fs.writeFileSync('./new.csv', newLines.join('\n'));
  28. });
Advertisement
Add Comment
Please, Sign In to add comment