package/package.json000666 0000000370 3560116604 011552 0ustar00000000 000000 { "name": "simple-string-table", "version": "1.0.0", "description": "it allows to create a simple impression of a table based on an array", "main": "index.js", "keywords": [ "console", "node" ], "author": "UpperCod", "license": "ISC" } package/index.js000666 0000000777 3560116604 010744 0ustar00000000 000000 module.exports = function table(rows, padding = 2) { let spaces = rows.reduce( (spaces, row) => row.reduce((spaces, value, index) => { value = "" + value; if (spaces[index] < value.length || spaces[index] == null) { spaces[index] = value.length; } return spaces; }, spaces), [] ); return rows .map(row => row .map( (value, index) => value + " ".repeat(spaces[index] - value.length + padding) ) .join("") ) .join("\n"); }; package/README.md000666 0000001174 3560116604 010546 0ustar00000000 000000 # simple-string-table It is created for the decoration of consoles, it allows to create a simple impression of a table based on an array, this script calculates the spaces of each column to justify the code. ```js let table = require("simple-string-table"); let example = table([ ["GZIP", "BRO", "FILE"], ["GZIP", "BRO123asdasdads", "FILE"], ["GZIP", "BRO", "FILE"], ["GZIP", "BRO12", "FILE"], ["GZIP", "BRO3", "FILE"] ]); console.log(example); ``` ```bash GZIP BRO FILE GZIP BRO123asdasdads FILE GZIP BRO FILE GZIP BRO12 FILE GZIP BRO3 FILE ```