+65
-53
@@ -14,2 +14,3 @@ var fs = require('fs'); | ||
| var that = this; | ||
| this.items = item; | ||
| config = config || {}; | ||
@@ -23,18 +24,27 @@ | ||
| if(item instanceof Object) { | ||
| if(item instanceof Array) { | ||
| // making the head | ||
| this.mkhead(item); | ||
| // making the head | ||
| this.mkhead(item); | ||
| // making the body | ||
| this.mkbody(item, function(err, result) { | ||
| if(err) throw new Error(err); | ||
| that.whole(config, function(err_whole, table) { | ||
| if(err) throw new Error(err_whole); | ||
| // making the body | ||
| this.mkbody(item, function(err, result) { | ||
| if(err) throw new Error(err); | ||
| that.whole(config, function(err, table) { | ||
| if(err) throw new Error(err); | ||
| that.table = table; | ||
| cb(that) | ||
| }) | ||
| }); | ||
| } else { | ||
| this.whole(config, function(err, table) { | ||
| if(err) | ||
| throw new Error(err); | ||
| that.table = table; | ||
| cb(that) | ||
| cb(that); | ||
| }) | ||
| }); | ||
| } | ||
| }else { | ||
| var load_json = this.load(item); | ||
| var parse = JSON.parse(load_json); | ||
| this.items = parse; | ||
| this.mkhead(parse); | ||
@@ -72,17 +82,39 @@ this.mkbody(parse, function(err, result) { | ||
| if (obj instanceof Array) { | ||
| // an array | ||
| async.each(obj, function(val, cb) { | ||
| var each_arr = []; | ||
| // an array | ||
| async.each(obj, function(val, cb) { | ||
| var each_arr = []; | ||
| Object.keys(val).forEach(function(key) { | ||
| each_arr.push(val[key]); | ||
| }) | ||
| Object.keys(val).forEach(function(key) { | ||
| each_arr.push(val[key]); | ||
| }) | ||
| that.body.push(each_arr); | ||
| that.body.push(each_arr); | ||
| cb(); | ||
| }, function(err) { | ||
| if(err) { | ||
| console.error(err); | ||
| }else { | ||
| callback(null, that.body); | ||
| } | ||
| }) | ||
| } | ||
| // make a whole table | ||
| JsonTb.prototype.whole = function(config, callback) { | ||
| var that = this; | ||
| var table_obj = config | ||
| if (this.items instanceof Array) { | ||
| table_obj.head = that.head; | ||
| var table = new Table(table_obj); | ||
| async.each(that.body, function(item, cb) { | ||
| table.push(item); | ||
| cb(); | ||
| }, function(err) { | ||
@@ -92,44 +124,24 @@ if(err) { | ||
| }else { | ||
| callback(null, that.body); | ||
| callback(null, table) | ||
| } | ||
| }) | ||
| } else { | ||
| var table = new Table(table_obj); | ||
| var arr = []; | ||
| var that = this; | ||
| // an object | ||
| var each_arr = []; | ||
| Object.keys(obj).forEach(function(key) { | ||
| each_arr.push(obj[key]); | ||
| Object.keys(this.items).forEach(function(key) { | ||
| var item_obj = {}; | ||
| item_obj[key] = that.items[key] | ||
| arr.push(item_obj); | ||
| }) | ||
| that.body.push(each_arr); | ||
| callback(null, that.body); | ||
| for (var i = 0; i < arr.length; i++) { | ||
| table.push(arr[i]); | ||
| }; | ||
| callback(null, table); | ||
| } | ||
| } | ||
| // make a whole table | ||
| JsonTb.prototype.whole = function(config, callback) { | ||
| var that = this; | ||
| var table_obj = config | ||
| table_obj.head = that.head; | ||
| var table = new Table(table_obj); | ||
| async.each(that.body, function(item, cb) { | ||
| table.push(item); | ||
| cb(); | ||
| }, function(err) { | ||
| if(err) { | ||
| console.error(err); | ||
| }else { | ||
| callback(null, table) | ||
| } | ||
| }) | ||
| } | ||
| JsonTb.prototype.show = function() { | ||
@@ -136,0 +148,0 @@ var table = this.table; |
+1
-1
| { | ||
| "name": "json-table", | ||
| "version": "0.1.1", | ||
| "version": "0.1.3", | ||
| "description": "Json table is an easy way to preview your json data in table", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,12 +40,2 @@ var json_tb = require('..'); | ||
| var json_tb_out = new json_tb(test_json, | ||
| { | ||
| chars: { 'top': '═' , 'top-mid': '╤' , 'top-left': '╔' , 'top-right': '╗' | ||
| , 'bottom': '═' , 'bottom-mid': '╧' , 'bottom-left': '╚' , 'bottom-right': '╝' | ||
| , 'left': '║' , 'left-mid': '╟' , 'mid': '─' , 'mid-mid': '┼' | ||
| , 'right': '║' , 'right-mid': '╢' , 'middle': '│' } | ||
| }, function(json_tb) { | ||
| }) | ||
| describe('check if the table is generated (input json object)', function() { | ||
@@ -88,3 +78,3 @@ | ||
| json_tb.table.should.be.instanceOf(Object) | ||
| }) | ||
| }) | ||
| }) | ||
@@ -91,0 +81,0 @@ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
430
1.9%39957
-0.22%