table-to-string
Generates a string representation of a table.
Installation
npm install table-to-string
yarn add table-to-string
Usage
const tableToString = require('table-to-string');
const isThatA = [
['Jotaro Kujo', 'Star Platinum'],
['Josuke Higashikata', 'Crazy Diamond'],
['Giorno Giovanna', 'Gold Experience Requiem'],
['Jolyne Cujoh', 'Stone Free'],
['Johnny Joestar', 'Tusk'],
];
tableToString(isThatA);
const jojoReference = [
['Dio', 'The World'],
['Yoshikage Kira', 'Killer Queen'],
['Diavolo', 'King Crimson'],
['Enrico Pucci', 'Made in Heaven'],
['Funny Valentine', 'Dirty Deeds Done Dirt Cheap'],
];
tableToString(jojoReference, {
align: ['r', 'c'],
str: (item) => `"${item}"`,
sep: ' | ',
});
Options
Name | Type | Default value | Description |
---|
align | ('l' | 'c' | 'r' | undefined)[] | [] (which is equivalent to ['l', 'l', 'l', ...] ) | The alignment for each column. It can be 'l' (left), 'c' (center) or 'r' (right). undefined is considered 'l' . |
len | (item: string, column: number) => number | (item) => item.length | The function used to get the item length. |
str | (item: any, column: number) => string | String(item != null ? item : '') | The function used to transform the item into a string. |
sep | string | ' ' (two whitespaces) | The separator between each item. |
lf | string | '\n' | The line feed used for new lines. |
License
This package is under a MIT license.