{"id":16636804,"url":"https://github.com/takamin/list-it","last_synced_at":"2025-03-21T15:31:50.206Z","repository":{"id":7851973,"uuid":"55449168","full_name":"takamin/list-it","owner":"takamin","description":"Converts arrays or objects to a Table for CLI","archived":false,"fork":false,"pushed_at":"2023-07-18T20:24:43.000Z","size":936,"stargazers_count":8,"open_issues_count":5,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-14T12:34:51.286Z","etag":null,"topics":["cli","number-alignment","table"],"latest_commit_sha":null,"homepage":"http://takamints.hatenablog.jp/entry/npm-list-it-preformatted-text-table-generator","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takamin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-04T22:13:20.000Z","updated_at":"2024-06-18T17:26:09.794Z","dependencies_parsed_at":"2024-06-18T17:26:03.974Z","dependency_job_id":"0d1a3e66-ecb9-482a-8a61-571f499fbb5e","html_url":"https://github.com/takamin/list-it","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Flist-it","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Flist-it/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Flist-it/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Flist-it/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takamin","download_url":"https://codeload.github.com/takamin/list-it/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221816420,"owners_count":16885334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","number-alignment","table"],"created_at":"2024-10-12T06:22:54.244Z","updated_at":"2024-10-28T10:21:46.702Z","avatar_url":"https://github.com/takamin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"list-it - Fixed Column Text Table Formatter\n===========================================\n\n\u003cspan class=\"display:inline-block;\"\u003e ![version](https://img.shields.io/npm/v/list-it)\n![license](https://img.shields.io/npm/l/list-it)\n[![Build Status](https://travis-ci.org/takamin/list-it.svg?branch=master)](https://travis-ci.org/takamin/list-it)\n[![Coverage Status](https://coveralls.io/repos/github/takamin/list-it/badge.svg?branch=master)](https://coveralls.io/github/takamin/list-it?branch=master)\n![node version](https://img.shields.io/node/v/list-it)\n\u003c/span\u003e  \n\u003cspan class=\"display:inline-block;\"\u003e\u003cspan class=\"label\"\u003enpm:\u003c/span\u003e\n![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/list-it)\n![weekly downloads](https://img.shields.io/npm/dw/list-it)\n![monthly downloads](https://img.shields.io/npm/dm/list-it)\n\u003c/span\u003e  \n\u003cspan class=\"display:inline-block;\"\u003e\u003cspan class=\"label\"\u003eGitHub:\u003c/span\u003e\n![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/takamin/list-it)\n![open issues](https://img.shields.io/github/issues-raw/takamin/list-it)\n![closed issues](https://img.shields.io/github/issues-closed-raw/takamin/list-it)\n![top language](https://img.shields.io/github/languages/top/takamin/list-it)\n![last commit](https://img.shields.io/github/last-commit/takamin/list-it)\n\u003c/span\u003e\n\nDESCRIPTION\n-----------\n\nThis module creates a text table string.\nAnd offers a cli command `listit` that print arrays in a json file to console\nas a table.\n\n* Each columns are aligned in vertical.\n* All number data in column are aligned by its fraction point with `autoAlign` option.\n* Longer text can be truncated with `setColumnWidth` option.\n\nCLI Command `listit`\n--------------------\n\n### INSTALL\n\nInstall with npm.\n\n```bash\n$ npm install --global list-it\n```\n\n### USAGE\n\n```bash\n$ listit --help\nUsage: listit [input-filename] [OPTIONS]\n\nOutputs the array included in JSON to the console in tabular format.\nNon-array data is displayed as is.\n\nOPTIONS:\n  -h, --help    Print this help message\n  -v, --version Print the version of this package\n\n----\nThis command is included in the npm list-it@1.2.0\n\nRepository: https://github.com/takamin/list-it\nHomepage: http://takamints.hatenablog.jp/entry/npm-list-it-preformatted-text-table-generator\n\nCopyright (c) 2020 Koji Takami\nThis software is released under the MIT License\n```\n\n### SAMPLE\n\nThe `listit` would print all data in the JSON file with its property name.\nIn following example, `$` means root oject.\n\n![listit sample/planets.json output](https://takamin.github.io/list-it/images//sample-listit-cli-command-output.png)\n\nUsing the exported ListIt class\n-------------------------------\n\n### PROGRAMMING SAMPLE\n\n__[sample/japanese-food.js](sample/japanese-food.js)__\n\n```javascript\nvar ListIt = require(\"list-it\");\nvar buf = new ListIt();\nbuf.setColumnWidth(1, 5);\nbuf.setColumnWidth(2, 15);\nbuf.setColumnWidth(3, 7);\nconsole.log(\n    buf\n        .d(\"1\").d(\"Sushi\")\n            .d(\"vinegared rice combined raw seafood\")\n            .d(\"Healthy\").nl()\n        .d(\"2\").d(\"Yakiniku\")\n            .d(\"Grilled meat on Japanese\")\n            .d(\"Juicy\").nl()\n        .d(\"3\").d(\"Ramen\")\n            .d(\"Japanese noodle soup dish\")\n            .d(\"I like it\").nl()\n        .d(\"4\").d(\"Tempura\")\n            .d(\"Deep fried seafood or vegetables\")\n            .d(\"Delicious\").nl()\n        .d(\"5\").d(\"Sashimi\")\n            .d(\"Very fresh sliced fish\")\n            .d(\"Try it now, It's good\").nl()\n        .toString());\n```\n\noutputs:\n\n```bash\n$ node sample/japanese-food.js\n1 Sushi vinegared rice  Healthy\n2 Yakin Grilled meat on Juicy\n3 Ramen Japanese noodle I like\n4 Tempu Deep fried seaf Delicio\n5 Sashi Very fresh slic Try it\n```\n\n#### autoAlign and setHeaderRow\n\n__[sample/planets.js](sample/planets.js)__\n\n```javascript\nconst ListIt = require(\"list-it\");\nconst listit = new ListIt({\n    autoAlign : true,\n    headerUnderline: true,\n});\nconst PLANETS = [\n    [\"NAME\", \"Mass(10^24kg)\", \"Dia(km)\", \"Dens(kg/m3)\",\n                        \"Grav(m/s2)\", \"EscV(km/s)\", \"Rot(hours)\" ],\n    [\"MERCURY\", 0.33,   4879,   5427,   3.7,    4.3,    1407.6  ],\n    [\"VENUS\",   4.87,   12104,  5243,   8.9,    10.4,   -5832.5 ],\n    [\"EARTH\",   5.97,   12756,  5514,   9.8,    11.2,   23.9    ],\n    [\"MOON\",    0.0073, 3475,   3340,   1.6,    2.4,    655.7   ],\n    [\"MARS\",    0.642,  6792,   3933,   3.7,    5.0,    24.6    ],\n    [\"JUPITER\", 1898,   142984, 1326,   23.1,   59.5,   9.9     ],\n    [\"SATURN\",  568,    120536, 687,    9.0,    35.5,   10.7    ],\n    [\"URANUS\",  86.8,   51118,  1271,   8.7,    21.3,   -17.2   ],\n    [\"NEPTUNE\", 102,    49528,  1638,   11.0,   23.5,   16.1    ],\n    [\"PLUTO\",   0.0146, 2370,   2095,   0.7,    1.3,    -153.3  ]\n];\n\nconsole.log(listit\n    .setHeaderRow(PLANETS.shift())\n    .d(PLANETS).toString()\n);\n```\n\noutputs:\n\n```bash\n$ node sample/planets.js\nNAME    Mass(10^24kg) Dia(km) Dens(kg/m3) Grav(m/s2) EscV(km/s) Rot(hours)\n------- ------------- ------- ----------- ---------- ---------- ----------\nMERCURY        0.33      4879        5427        3.7        4.3     1407.6\nVENUS          4.87     12104        5243        8.9       10.4    -5832.5\nEARTH          5.97     12756        5514        9.8       11.2       23.9\nMOON           0.0073    3475        3340        1.6        2.4      655.7\nMARS           0.642     6792        3933        3.7        5.0       24.6\nJUPITER     1898.0     142984        1326       23.1       59.5        9.9\nSATURN       568.0     120536         687        9.0       35.5       10.7\nURANUS        86.8      51118        1271        8.7       21.3      -17.2\nNEPTUNE      102.0      49528        1638       11.0       23.5       16.1\nPLUTO          0.0146    2370        2095        0.7        1.3     -153.3\n```\n\n#### Exponential notation\n\n__[sample/atoms.js](sample/atoms.js)__\n\n```javascript\nconst ListIt = require(\"ist-it.js\");\nconst listit = new ListIt({\n    autoAlign : true,\n    headerUnderline: true,\n});\nconst ATOMS = [\n    [\"Name\", \"Radius(m)\", \"Radius(Å)\"],\n    [\"H\", 0.1e-10, 0.1],\n    [\"Cl\", 1.67e-10, 1.67],\n    [\"Na\", 1.16e-10, 1.16],\n    [\"O\", 1.21e-10, 1.21],\n    [\"Si\", 0.4e-10, 0.4],\n];\n\nconsole.log(listit.setHeaderRow(ATOMS.shift()).d(ATOMS).toString());\n```\n\noutputs:\n\n```bash\n$ node sample/atoms.js\nName Radius(m) Radius(Å)\n---- --------- ---------\nH     1.00e-11      0.1\nCl    1.67e-10      1.67\nNa    1.16e-10      1.16\nO     1.21e-10      1.21\nSi    4.00e-11      0.4\n```\n\n#### Object Array\n\n\n__[sample/planets-obj.js](sample/planets-obj.js)__\n\n```javascript\nconst ListIt = require(\"../index.js\");\nconst list = new ListIt({\n    headerBold: true,\n    headerColor: \"green\",\n    headerUnderline: true,\n});\nconst PLANETS = [\n    { name: \"MERCURY\", mass: 0.33, dia: 4879, dens: 5427,\n        grav: 3.7, escV: 4.3, rot: 1407.6 },\n    { name: \"VENUS\", mass: 4.87, dia: 12104, dens: 5243,\n        grav: 8.9, escV: 10.4, rot: -5832.5 },\n    { name: \"EARTH\", mass: 5.97, dia: 12756, dens: 5514,\n        grav: 9.8, escV: 11.2, rot: 23.9 },\n    { name: \"MOON\", mass: 0.0073, dia: 3475, dens: 3340,\n        grav: 1.6, escV: 2.4, rot: 655.7 },\n    { name: \"MARS\", mass: 0.642, dia: 6792, dens: 3933,\n        grav: 3.7, escV: 5.0, rot: 24.6 },\n    { name: \"JUPITER\", mass: 1898, dia: 142984, dens: 1326,\n        grav: 23.1, escV: 59.5, rot: 9.9 },\n    { name: \"SATURN\", mass: 568, dia: 120536,dens: 687,\n        grav: 9.0, escV: 35.5, rot: 10.7 },\n    { name: \"URANUS\", mass: 86.8, dia: 51118, dens: 1271,\n        grav: 8.7, escV: 21.3, rot: -17.2 },\n    { name: \"NEPTUNE\", mass: 102, dia: 49528, dens: 1638,\n        grav: 11.0, escV: 23.5, rot: 16.1 },\n    { name: \"PLUTO\", mass: 0.0146, dia: 2370, dens: 2095,\n        grav: 0.7, escV: 1.3, rot: -153.3 }\n];\nconsole.log( list.d( PLANETS ).toString() );\n```\n\noutputs:\n\n![sample/planets-obj.js outputs](https://takamin.github.io/list-it/images/sample-planets-obj-js-output.png)\n\n\n#### East asian characters\n\n__[sample/japanese-food-jp.js](sample/japanese-food-jp.js)__\n\n```javascript\nvar ListIt = require(\"list-it\");\nvar buf = new ListIt();\nconsole.log(\n    buf\n        .d(\"1\").d(\"寿司\")\n            .d(\"酢とご飯とシーフード\")\n            .d(\"健康的だ\").nl()\n        .d(\"2\").d(\"焼肉\")\n            .d(\"日本のグリルされたお肉\")\n            .d(\"ジューシー\").nl()\n        .d(\"3\").d(\"ラーメン\")\n            .d(\"日本のスープに入った麺\")\n            .d(\"大好き\").nl()\n        .d(\"4\").d(\"天ぷら\")\n            .d(\"シーフードや野菜に衣をつけて揚げたもの\")\n            .d(\"おいしー\").nl()\n        .d(\"5\").d(\"刺身\")\n            .d(\"大変フレッシュな魚のスライス\")\n            .d(\"食べてみて！あご落ちるぜ\").nl()\n        .toString());\n```\n\noutputs:\n\n```bash\n$ node sample/japanese-food-jp.js\n1 寿司     酢とご飯とシーフード                   健康的だ\n2 焼肉     日本のグリルされたお肉                 ジューシー\n3 ラーメン 日本のスープに入った麺                 大好き\n4 天ぷら   シーフードや野菜に衣をつけて揚げたもの おいしー\n5 刺身     大変フレッシュな魚のスライス           食べてみて！あご落ちるぜ\n```\n\n\nAPI Reference\n------------\n\n### Class ListIt\n\n#### CONSTRUCTOR\n\n* __ListIt(options)__\n\n#### OPTIONS\n\n* __autoAlign__ - Specifies the number data alignment.\n* __columnWidth__ - Initializes the text max length for all columns.\n* __header__ - Sets a column header row.\n* __headerBold__ - Renders the header bold.\n* __headerColor__ - Specify header text color.\n* __headerUnderline__ - Draws a line under the header text.\n* __headerBold__ - Make header text bold.\n* __headerColor__ - Set color to the header text.\n* __headerUnderline__ - Add underline to the header text.\n\n#### METHODS\n\n* __setColumnWidth__ - Sets a text max length to a column.\n* __setColumnWidthAll__ - Sets text max length to all columns.\n* __setHeaderRow__ - Set the column header row.\n* __d__ - Add cells or rows\n* __nl__ - New line\n* __toString__ - Format a table\n\n### Constructor ListIt(opt)\n\n__`const listit = new ListIt(opt)`__\n\nCreates a `ListIt` instance.\n\nThe instance has current row that is a position for the columns to be added.\n\nTo add a cell, use 'd' method. Check the samples above.\n\n### OPTION.autoAlign\n\n__`autoAlign:boolean` (Default: `true`)__\n\nWhen this is set true, the data in cell will be aligned in Automatic depending on its type.\nThe number will be aligned to the right taking account of its decimal point.\n\n### OPTION.columnWidth\n\n__`columnWidth:Array\u003cnumber\u003e|number|null` (Default: `null`)__\n\nDeclare text width for columns by character length (or remove).\n\n* __Set a Width For Each Columns__ - An array of numbers could be specified.\nIts each elements are set to the column at that position.\nA `null` as the element value means that width will not be specified.\n* __Set a Width For All Columns__ - If a single number is specified for this option, It will set to all columns.\nAnd also when the value is null, column width is not declared at all.\n\n### OPTION.header\n\n__`header:Array\u003cany\u003e|null` (Default: `null`)__\n\nSets a column header row with array.\n\nEven if the header is not specified, it might be created in the method `d` running.\nThis header-auto-creation feature will be activated when following two condition is true.\n\n* The parameter for the `d` method is an object array.\n* One or more header-relating-options except for `header` are set.\n\n\n### OPTION.headerBold\n\n__`headerBold:boolean` (Default: `false`)__\n\nThis option makes the header text to render bold.\nBut, actual appearance would be dependent on the terminal.\n\nIf the header does not exists, no effect is appeared.\n\n### OPTION.headerColor\n\n__`headerColor:string|null` (Default: `null`)__\n\nWith this option, specify the color of the header text with color names.\nBut, actual appearance would be dependent on the terminal.\n\nIf the header does not exists, no effect is appeared.\n\nAvailable color names:\n\n* \"black\"\n* \"red\"\n* \"green\"\n* \"yellow\"\n* \"blue\"\n* \"magenta\"\n* \"cyan\"\n* \"white\"\n* \"grey\"\n* \"gray\"\n* \"brightRed\"\n* \"brightGreen\"\n* \"brightYellow\"\n* \"brightBlue\"\n* \"brightMagenta\"\n* \"brightCyan\"\n* \"brightWhite\"\n\n\n### OPTION.headerUnderline\n\n__`headerUnderline:boolean` (Default: `false`)__\n\nWhen this option is true, an underline will be drawn for the header text.\n\nIf the header does not exists, no effect is appeared.\n\n### ListIt#setColumnWidth\n\n__`setColumnWidth(indexOfColumns:number, width:number)`__\n\nSet the column width by text length.\n\nThe actual width is calculated by traversing all data in a column.\nA number data never be affected, because it should not be truncated.\nSo it may be longer than the specified length when some number data\nexist in a column.\n\nPARAMETERS:\n\n1. `indexOfColumns` - a column index to set.\n2. `width` - a character length of the column.\n    If `null` is specified, the declaration is removed.\n\nRETURN VALUE:\n\nThis method returns `this` instance to chain the next method call.\n\n### ListIt#setColumnWidthAll\n\n__`setColumnWidthAll(widthForAll:Array\u003cnumber|null\u003e|number|null)`__\n\nSet the whole column's width. See opt.columnWidth\n\nPARAMETERS:\n\n1. `widthForAll` - An array of widtha.\n\nRETURN VALUE:\n\nThis method returns `this` instance to chain the next method call.\n\n### ListIt#setHeaderRow\n\n__`setHeaderRow(header:Array\u003cany\u003e|null)`__\n\nWith this method, set the column header row.\nFor the parameter, it is same as OPTION.header.\nIf null is specified, the header would be removed.\n\n### ListIt#d\n\n__`d( data [, data ...] )`__\n\nThis method adds one or more columns or rows at a time depending on\nthe parameter data type.\n\nThis method returns `this` object. So you can chain to call a next method.\n\n#### To Add column(s)\n\nIf the type of `data` is a primitive type such as string or number,\nthese are added to the current row as individual columns.\n\nThis operation will not add a new line in automatic.\nA code of below outputs only one row containing six column from 1 to 6.\n\n```\nCODE: buffer.d(1,2,3).d(4,5,6).nl();\n\nOUTPUT: \"1 2 3 4 5 6\"\n```\n\nThe above code make same result as below:\n\n```\nEQUIVALENT CODE: buffer.d(1,2,3,4,5,6).nl();\n```\n\n#### To add row(s)\n\nIf the parameter `data` is an array contains one or more primitive data at least,\nit will added as one closed row.\n\nBut if the type of all elements of the array is an array,\nin other words it is two or more dimensional array,\neach elements are added as a row.\n\nNOTE: A new-line will never be added before the addition.\nSo, If the previous row was not closed, you must call the `nl()` method.\n\nThe following sample outputs two rows:\n\n```\nCODE: buffer.d( [1,2,3], [4,5,6] );\n\nOUTPUT:\"1 2 3\\n4 5 6\"\n\nEQUIVALENT CODE: buffer.d([ [1,2,3], [4,5,6] ]);\n```\n\n\n### ListIt#nl\n\n__`nl()`__\n\nEnds up a process for the current row.\n\nThis method also returns `this` object.\n\n### ListIt#toString\n\n__`toString()`__\n\nReturns preformatted text table.\n\n\nLICENSE\n-------\n\nThis software is released under the MIT License, see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakamin%2Flist-it","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakamin%2Flist-it","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakamin%2Flist-it/lists"}