xlsx-to-json
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -9,4 +9,3 @@ var fs = require('fs'); | ||
function XLSX_json (config) { | ||
console.log(config) | ||
function XLSX_json (config, callback) { | ||
if(!config.input) { | ||
@@ -17,17 +16,11 @@ console.error("You miss a input file"); | ||
if(!config.output) { | ||
console.error("You miss a output file"); | ||
process.exit(2); | ||
} | ||
var cv = new CV(config); | ||
var cv = new CV(config, callback); | ||
} | ||
function CV(config) { | ||
function CV(config, callback) { | ||
var wb = this.load_xlsx(config.input) | ||
var ws = this.ws(wb); | ||
var csv = this.csv(ws) | ||
this.cvjson(csv, config.output) | ||
this.cvjson(csv, config.output, callback) | ||
} | ||
@@ -52,3 +45,3 @@ | ||
CV.prototype.cvjson = function(csv, output) { | ||
CV.prototype.cvjson = function(csv, output, callback) { | ||
cvcsv() | ||
@@ -77,5 +70,10 @@ .from.string(csv) | ||
console.log('Number of lines: '+count); | ||
var stream = fs.createWriteStream(output, { flags : 'w' }); | ||
stream.write(JSON.stringify(record)); | ||
if(output !== null) { | ||
var stream = fs.createWriteStream(output, { flags : 'w' }); | ||
stream.write(JSON.stringify(record)); | ||
callback(null, record); | ||
}else { | ||
callback(null, record); | ||
} | ||
}) | ||
@@ -82,0 +80,0 @@ .on('error', function(error){ |
{ | ||
"name": "xlsx-to-json", | ||
"version": "0.0.0", | ||
"description": "", | ||
"version": "0.0.1", | ||
"description": "Convert xlsx to json", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -18,5 +18,13 @@ # node-xlsx-json | ||
output: "output.json" | ||
}, function(err, result) { | ||
if(err) { | ||
console.error(err); | ||
}else { | ||
console.log(result); | ||
} | ||
}); | ||
``` | ||
In config object, you have to enter an input path. But If you don't want to output any file you can set to `null`. | ||
## License | ||
@@ -23,0 +31,0 @@ |
@@ -6,3 +6,10 @@ var xlsx_json = require('../') | ||
output: __dirname + '/test.json' | ||
}, function(err, result) { | ||
if(err) { | ||
console.error(err); | ||
}else { | ||
console.log(result); | ||
} | ||
}); | ||
16253
80
34