Giter VIP home page Giter VIP logo

node-tableify's Introduction

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"' [email protected]

license

MIT

node-tableify's People

Contributors

gochomugo avatar troy-lamerton avatar wankdanker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-tableify's Issues

Option to not add classes

I am using tableify over here and the classes added by tableify are conflicting with my CSS (Bulma). Is it possible to get an option to disable adding the class names?

Add styling hooks, or at least table ID for CSS targeting

Love this package. I have a lot of tables that I need to display on the fly and would like this tool built out some more. In particular, styling. I'm thinking tableify() could take a styleOptions object that looks something like this:

const styleOptions = {
   tableStyle: "font-family: Helvetica, Arial, sans-serif; font-size: 11px; line-height: 20px;",
   trStyle: null,
   tdStyle: "padding: 4px 2px; text-align: left; vertical-align: top; background-color: #eaeaea;"
 }

These then get inserted into the tag with e.g. style="'" + styleOptions.tableStyle + "'"
Alternatively, one could specify the table ID to target it with CSS by passing the id to tableify(). So you could write tableify("myTableID")

...and then you could have CSS that targets, like

#myTableId table {
   font-weight: bold;
   font-size: 10px;
   font-weight: bold;
}

#myTableId td {
   vertical-align: top;
   text-align: left;
   float: left;
}

When the number of lines of json is nearly 45000

Hi,

We are trying to use this with results of axe. But html table is not rendered after someline when the records are more. This issue is not observed when the lines in json is less

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.