Rewrite of text-table in TypeScript, making it faster and smaller.
npm install fast-text-tableimport table from "fast-text-table";
// or
const table = require("fast-text-table");
const t = table([
["master", "0123456789abcdef"],
["staging", "fedcba9876543210"],
]);
console.log(t);Output:
master 0123456789abcdef
staging fedcba9876543210table(
[
["beep", "1024"],
["boop", "33450"],
["foo", "1006"],
["bar", "45"],
],
{ align: ["l", "r"] }
);beep 1024
boop 33450
foo 1006
bar 45table(
[
["beep", "1024"],
["boop", "334.212"],
["foo", "1006"],
["bar", "45.6"],
["baz", "123."],
],
{ align: ["l", "."] }
);beep 1024
boop 334.212
foo 1006
bar 45.6
baz 123.table(
[
["beep", "1024", "xyz"],
["boop", "3388450", "tuv"],
["foo", "10106", "qrstuv"],
["bar", "45", "lmno"],
],
{ align: ["l", "c", "l"] }
);beep 1024 xyz
boop 3388450 tuv
foo 10106 qrstuv
bar 45 lmnorowsany[][]- Array of rows to format.optsobject- Optional options object.opts.hsepstring- Horizontal separator. Default:" ".opts.alignstring[]- Array of alignment types for each column. Default:["l", "l", ..., "l"].l- Leftr- Rightc- Center.- Dotted
opts.stringLengthfunction- Custom string length function. Default:s => s.length.
clk: ~4.02 GHz
cpu: 13th Gen Intel(R) Core(TM) i5-13400F
runtime: node 24.11.1 (x64-win32)
benchmark avg (min … max) p75 / p99 (min … top 1%)
------------------------------------------- -------------------------------
• table - small dataset
------------------------------------------- -------------------------------
fast-text-table 4.95 µs/iter 4.85 µs 5.92 µs ▂█▆▁▁▁▁▁▂▂▂
text-table-fast 6.95 µs/iter 7.01 µs 7.58 µs ▃▃▂▆██▄▁▁▁▃
text-table 20.53 µs/iter 20.69 µs 20.94 µs █▁▅▁█▅▅█▅▁▅
summary
fast-text-table
1.41x faster than text-table-fast
4.15x faster than text-table
• table - middle dataset
------------------------------------------- -------------------------------
fast-text-table 270.59 µs/iter 286.70 µs 395.00 µs ▁▇█▅▇▃▃▂▂▁▂
text-table-fast 432.70 µs/iter 447.60 µs 571.40 µs ▂█▄▄▂▂▁▁▁▁▁
text-table 7.03 ms/iter 7.13 ms 7.34 ms ▂▃▅▅█▆▅▄▃▂▂
summary
fast-text-table
1.6x faster than text-table-fast
26x faster than text-table
• table - large dataset
------------------------------------------- -------------------------------
fast-text-table 9.69 ms/iter 9.86 ms 10.02 ms ▃▄▅█▅▃▅▅▆▅▂
text-table-fast 47.22 ms/iter 47.69 ms 47.97 ms ▃▆▁▆▆█▆█▆█▆
text-table 5.42 s/iter 5.44 s 5.44 s ▃▁▁▁█▅▁▁▃▁▆
summary
fast-text-table
4.88x faster than text-table-fast
559.9x faster than text-table
MIT