Last active
November 3, 2016 01:16
-
-
Save code-for-coffee/0793992d6a521b813db3ac1aa373df73 to your computer and use it in GitHub Desktop.
ExoplanetClass
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
/** | |
* Created by codeforcoffee on 11/2/16. | |
*/ | |
const Converter = require("csvtojson").Converter; | |
const fs = require('fs'); | |
const path = require('path'); | |
class CSVObectifier { | |
constructor(csvFileData) { | |
this.converter = new Converter({}); | |
this.csv = csvFileData; | |
}; | |
convert(callback) { | |
this.converter.fromString(this.csv, function(err, json){ | |
callback(json); | |
}); | |
}; | |
writeFile(filename) { | |
if (!filename) filename = 'default.json'; | |
var x = (result) => { | |
console.log(result); | |
fs.writeFileSync(filename, JSON.stringify(result), 'utf8'); | |
}; | |
this.convert(x); | |
}; | |
}; | |
// test our class and verify things work | |
var data = fs.readFileSync(path.join(__dirname, 'planets.csv'), { encoding : 'utf8'}); | |
console.log(data); | |
let x = new CSVObectifier(data); | |
x.writeFile('data.json'); | |
//module.exports = CSVObectifier; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment