1.0.0 • Published 1 year ago
kochedacliutils v1.0.0
Kocheda CLI Utils
This library provides some simple command line interface utilities.
Example Usage
npm install kochedacliutils
Then in code
const cliutils = require("kochedacliutils");
console.log(cliutils.COLOURS.blue + "This is blue" + cliutils.COlOURS.clear);
Console Colours
An object called 'COLOURS' provides the following console escape codes to generate colour:
COLOURS.black
COLOURS.red
COLOURS.green
COLOURS.yellow
COLOURS.blue
COLOURS.magenta
COLOURS.cyan
COLOURS.white
COLOURS.boldblack
COLOURS.boldred
COLOURS.boldgreen
COLOURS.boldyellow
COLOURS.boldblue
COLOURS.boldmagenta
COLOURS.boldcyan
COLOURS.boldwhite
COLOURS.clear
Table Generation
The arrayToTable() function converts 2 dimensional arrays into a formatted string which will display as an aligned table in the console along with optional lines. The function provides the following:
- All cells in table are aligned/padded
- Configurable cell padding
- Optional lines
- Missing cell data in rows is automatically added
- Non-string cell content is stringified
Examples
The simplest example is just a 2 dimensional array of content:
console.log(module.exports.arrayToTable([["Cell 1", "Cell 2", "Cell 3"], ["Example", "This is longer content", 12345],, ["JSON content", "Stringified", {"hello":"world"}]]));
Cell 1 Cell 2 Cell 3
Example This is longer content 12345
JSON content Stringified {"hello":"world"}
And the same data with lines and additional padding:
console.log(module.exports.arrayToTable([["Cell 1", "Cell 2", "Cell 3"], ["Example", "This is longer content", 12345],, ["JSON content", "Stringified", {"hello":"world"}]], {lines:true, padding:4}));
┌────────────────────┬──────────────────────────────┬─────────────────────────┐
│ Cell 1 │ Cell 2 │ Cell 3 │
├────────────────────┼──────────────────────────────┼─────────────────────────┤
│ Example │ This is longer content │ 12345 │
├────────────────────┼──────────────────────────────┼─────────────────────────┤
│ JSON content │ Stringified │ {"hello":"world"} │
└────────────────────┴──────────────────────────────┴─────────────────────────┘
1.0.0
1 year ago