Skip to content
Create HTML tables from JavaScript Objects
JavaScript HTML CSS
Branch: master
Clone or download
wankdanker Add defaults() function (issue #3)
This function accepts a config object with 'classes' and 'classPrefix' options.
Latest commit abc6daf Sep 16, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Fix Shebang Error Dec 18, 2014
.gitignore Fix Shebang Error Dec 18, 2014
README.md escape the style tag so it doesn't blow up MD renderers Aug 1, 2014
index.js Add defaults() function (issue #3) Sep 15, 2018
package.json 1.1.0 Aug 11, 2017
style.css Add css option for bin May 19, 2014
test.html update test to test for 2d Aug 11, 2017
test.js Add defaults() function (issue #3) Sep 15, 2018

README.md

node-tableify

From any JavaScript object, HTML tables create.

description

Given any Javascript object including Object, Array, Number, Date, null, undefined, primitives, etc, tableify generates HTML tables that represent each object. In the case of Arrays containing Objects (hash tables), it will generate a table with a header row containing the key names of the object found in the first element of the array.

Every value to be output to the table is processed through tableify recursively so objects containing other objects will result in tables within tables.

For each td cell that is created, a class is generated based on the constructor.name of the value, or null if the value is null.

install

npm install tableify

usage

var tableify = require('tableify');

var html = tableify({
	someArrayOfObjects : [
		{ a : 1, b : 2, c : 3  }
		, { a : 2, b : 3, c : 4 }
		, { a : 3, b : 4, c : 5 }
	]
	, someObject : {
		key1 : 'value1'
		, someArray : [
			'value2'
			, 'value3'
			, 'value4'
			, 'value5'
		]
		, someArrayOfObjects : [
			{ key2 : 123 }
			, { key2 : 234 }
			, { key2 : 345 }
		]
	}
});

console.log(html);

command line usage

When installed with npm install -g tableify you get the tablify command line utility. This is a simple command which accepts JSON from stdin and outputs html to stdout. I use it for emailing json files in a nice format for debugging purposes.

The --style option prepends a <style> tag with some default css

cat datafile.json | tableify --style | mutt -e 'set content_type="text/html"' me@myaddress.com

license

MIT

You can’t perform that action at this time.