Created
October 15, 2019 05:47
-
-
Save gerardo-junior/2dfda6b7557e1334d1ef2ba495c4ad7c to your computer and use it in GitHub Desktop.
Revisions
-
gerardo-junior revised this gist
Oct 15, 2019 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ // Author: Gerardo Junior <[email protected] // Date: 10/14/2019, 8:53:55 PM // URL: https://gist.github.com/gerardo-junior/2dfda6b7557e1334d1ef2ba495c4ad7c/ function csvParser(filename) { const fs = require('fs') , path = require('path') -
gerardo-junior created this gist
Oct 15, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ function csvParser(filename) { const fs = require('fs') , path = require('path') , filePath = path.join(__dirname, filename); return new Promise((resolve, reject) => { fs.readFile(filePath, { encoding: 'utf-8' }, function (err, file) { if (!err) { fileValues = file.split('\n') fileKeys = fileValues[0].split(',') fileValues.shift(); parser = [] fileValues.forEach(element => { parserCusor = {} element.split(',').forEach((element, index) => { parserCusor[fileKeys[index]] = element.trim() }); parser.push(parserCusor) }); resolve(parser) } else { reject(err) } }) }) }