totable

A tiny library that generates html tables from arrays of objects.

Usage no npm install needed!

<script type="module">
  import totable from 'https://cdn.skypack.dev/totable';
</script>

README

ToTable

A tiny library that generates html tables from arrays of objects.

No funny businesses, no dependencies, no transpilation, just ~50 lines of vanilla js.

Demo Fiddle

NPM

npm i --save totable

CDN

<script src="https://cdn.rawgit.com/Olian04/ToTable/d126873e/src/ToTable.js"></script>

ToTable(arrayOfObjects)

const ToTable = require('totable');

const html = ToTable([
  { firstname: 'Oliver', lastname: 'Twist', age: 14 },
  { firstname: 'Charles', lastname: 'Darwin', age: 78 },
  { firstname: 'Steven', lastname: 'Hawken', age: 50 }
]);
Firstname Lastname Age
Oliver Twist 14
Charles Darwin 78
Steven Hawkins 50

ToTable(arrayOfColumnNames, arrayOfObjects)

const ToTable = require('totable');

const html = ToTable(['lastname', 'age'], [
  { firstname: 'Oliver', lastname: 'Twist', age: 14 },
  { firstname: 'Charles', lastname: 'Darwin', age: 78 },
  { firstname: 'Steven', lastname: 'Hawken', age: 50 }
]);
Lastname Age
Twist 14
Darwin 78
Hawkins 50

ToTable(objectOfColumnNameMappings, arrayOfObjects)

const ToTable = require('totable');

const html = ToTable({
  firstname: 'name',
  age: 'age'
}, [
  { firstname: 'Oliver', lastname: 'Twist', age: 14 },
  { firstname: 'Charles', lastname: 'Darwin', age: 78 },
  { firstname: 'Steven', lastname: 'Hawken', age: 50 }
]);
name age
Oliver 14
Charles 78
Steven 50