console.table
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "console.table", | ||
"main": "index.js", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/bahmutov/console.html", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -48,2 +48,16 @@ (function () { | ||
function objectToArray(obj) { | ||
var keys = Object.keys(obj); | ||
return keys.map(function (key) { | ||
return { | ||
key: key, | ||
value: obj[key] | ||
}; | ||
}); | ||
} | ||
function objectToString(obj) { | ||
return arrayToString(objectToArray(obj)); | ||
} | ||
console.table = function () { | ||
@@ -63,2 +77,4 @@ var args = Array.prototype.slice.call(arguments); | ||
console.log(arrayToString(k)); | ||
} else if (typeof k === 'object') { | ||
console.log(objectToString(k)); | ||
} | ||
@@ -65,0 +81,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";function a(){function a(a){var b=new c;return a.forEach(function(a){"string"==typeof a||"number"==typeof a?b.cell("item",a):Object.keys(a).forEach(function(c){b.cell(c,a[c])}),b.newRow()}),b.toString()}function b(b,c){var d=a(c),e=d.indexOf("\n");if(e>0){b.length>e&&(e=b.length),console.log(b);var f,g="-",h="";for(f=0;e>f;f+=1)h+=g;console.log(h)}console.log(d)}if("undefined"==typeof console)throw new Error("Weird, console object is undefined");if("function"!=typeof console.table){var c=require("easy-table");console.table=function(){var c=Array.prototype.slice.call(arguments);return 2===c.length&&"string"==typeof c[0]&&Array.isArray(c[1])?b(c[0],c[1]):void c.forEach(function(b){return"string"==typeof b?console.log(b):void(Array.isArray(b)&&console.log(a(b)))})}}}a()}(); | ||
!function(){"use strict";function a(){function a(a){var b=new e;return a.forEach(function(a){"string"==typeof a||"number"==typeof a?b.cell("item",a):Object.keys(a).forEach(function(c){b.cell(c,a[c])}),b.newRow()}),b.toString()}function b(b,c){var d=a(c),e=d.indexOf("\n");if(e>0){b.length>e&&(e=b.length),console.log(b);var f,g="-",h="";for(f=0;e>f;f+=1)h+=g;console.log(h)}console.log(d)}function c(a){var b=Object.keys(a);return b.map(function(b){return{key:b,value:a[b]}})}function d(b){return a(c(b))}if("undefined"==typeof console)throw new Error("Weird, console object is undefined");if("function"!=typeof console.table){var e=require("easy-table");console.table=function(){var c=Array.prototype.slice.call(arguments);return 2===c.length&&"string"==typeof c[0]&&Array.isArray(c[1])?b(c[0],c[1]):void c.forEach(function(b){return"string"==typeof b?console.log(b):void(Array.isArray(b)?console.log(a(b)):"object"==typeof b&&console.log(d(b)))})}}}a()}(); |
16
index.js
@@ -48,2 +48,16 @@ (function () { | ||
function objectToArray(obj) { | ||
var keys = Object.keys(obj); | ||
return keys.map(function (key) { | ||
return { | ||
key: key, | ||
value: obj[key] | ||
}; | ||
}); | ||
} | ||
function objectToString(obj) { | ||
return arrayToString(objectToArray(obj)); | ||
} | ||
console.table = function () { | ||
@@ -63,2 +77,4 @@ var args = Array.prototype.slice.call(arguments); | ||
console.log(arrayToString(k)); | ||
} else if (typeof k === 'object') { | ||
console.log(objectToString(k)); | ||
} | ||
@@ -65,0 +81,0 @@ }); |
{ | ||
"name": "console.table", | ||
"description": "Adds console.table method that prints an array of objects as a table in console", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -65,1 +65,21 @@ var expect = require('expect.js'); | ||
}); | ||
describe('console.table object', function () { | ||
beforeEach(function () { | ||
// make sure the module is loaded without caching | ||
delete require.cache[require.resolve('../index')]; | ||
require('../index'); | ||
}); | ||
afterEach(function () { | ||
delete console.table; | ||
}); | ||
it('prints an object', function () { | ||
console.table({ foo: 'foo', bar: 'bar' }); | ||
}); | ||
it('prints an object', function () { | ||
console.table('this is an object', { foo: 'foo', bar: 'bar' }); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19464
349