Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const parse = require('csv-parse');
- const parser = parse({
- delimiter: ',',
- });
- const ACTIONS = {
- DEPOSIT: 'Deposit',
- TRANSFER: 'Transfer',
- RECEIVE: 'Receive',
- PAYMENT: 'Payment',
- SWIPE: 'Swipe',
- };
- parse(fs.readFileSync('./ss.csv').toString(), {
- comment: '#',
- }, function (err, output) {
- const newLines = [];
- output.forEach(o => {
- const [dirtyDate, outAmount, inAmount, , note] = o;
- const [dd, mm, yy] = dirtyDate.trim().split(' ')[0].split('/');
- const cleanDate = [ Number(yy), String(Number(mm)).padStart(2,0), String(Number(dd)).padStart(2,0)].join('-');
- newLines.push(['Others', cleanDate, Number(outAmount.replace(/,/g, '')), Number(inAmount.replace(/,/g, '')), 'Note'].join(','));
- const newNote = {
- action: null,
- };
- });
- fs.writeFileSync('./new.csv', newLines.join('\n'));
- });
Advertisement
Add Comment
Please, Sign In to add comment