{"id":13426443,"url":"https://github.com/tecfu/tty-table","last_synced_at":"2025-04-08T09:07:31.222Z","repository":{"id":34411108,"uuid":"38341443","full_name":"tecfu/tty-table","owner":"tecfu","description":"Terminal table for Windows, Linux, and MacOS. Written in nodejs. Also works in browser console. Word wrap, padding, alignment, colors, Asian character support, per-column callbacks, and you can pass rows as objects or arrays. Backwards compatible with Automattic/cli-table.","archived":false,"fork":false,"pushed_at":"2023-10-29T19:50:40.000Z","size":4936,"stargazers_count":292,"open_issues_count":3,"forks_count":31,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T07:43:32.578Z","etag":null,"topics":["cli-table","nodejs","table","terminal-table","tty-table"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/tty-table","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/tecfu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2015-07-01T01:09:36.000Z","updated_at":"2025-03-22T11:12:16.000Z","dependencies_parsed_at":"2024-06-18T12:28:18.144Z","dependency_job_id":"42b82699-2ce1-459b-af45-3af40511c0af","html_url":"https://github.com/tecfu/tty-table","commit_stats":{"total_commits":411,"total_committers":18,"mean_commits":"22.833333333333332","dds":0.09002433090024331,"last_synced_commit":"a143770cb969160243a73032f7cccb79abead123"},"previous_names":[],"tags_count":83,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Ftty-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Ftty-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Ftty-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Ftty-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tecfu","download_url":"https://codeload.github.com/tecfu/tty-table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"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-table","nodejs","table","terminal-table","tty-table"],"created_at":"2024-07-31T00:01:34.641Z","updated_at":"2025-04-08T09:07:31.184Z","avatar_url":"https://github.com/tecfu.png","language":"JavaScript","readme":"# tty-table 端子台\n\n[![NPM version](https://badge.fury.io/js/tty-table.svg)](http://badge.fury.io/js/tty-table) [![Coverage Status](https://coveralls.io/repos/github/tecfu/tty-table/badge.svg?branch=master)](https://coveralls.io/github/tecfu/tty-table?branch=master)\n---\n\nDisplay your data in a table using a terminal, browser, or browser console.\n\n---\n\n## [Examples](examples/)\n\n[See here for complete example list](examples/)\n\n\nTo view all example output:\n\n```sh\n$ git clone https://github.com/tecfu/tty-table \u0026\u0026 cd tty-table \u0026\u0026 npm i\n$ npm run view-examples\n```\n\n### Terminal (Static)\n\n[examples/styles-and-formatting.js](examples/styles-and-formatting.js)\n\n![Static](https://cloud.githubusercontent.com/assets/7478359/15691679/07142030-273f-11e6-8f1e-25728d558a2d.png \"Static Example\") \n\n### Terminal (Streaming)\n\n```\n$ node examples/data/fake-stream.js | tty-table --format json --header examples/config/header.js\n```\n\n![Streaming](https://user-images.githubusercontent.com/7478359/51738817-47c25700-204d-11e9-9df1-04e478331658.gif \"tty-table streaming example\") \n\n- See the built-in help for the terminal version of tty-table with: \n```\n$ tty-table -h\n```\n\n### Browser \u0026 Browser Console \n\n- View in Chrome or Chromium at [http://localhost:8070/examples/browser-example.html](http://localhost:8070/examples/browser-example.html) using a dockerized apache instance:\n\n    ```sh\n    git clone https://github.com/tecfu/tty-table\n    cd tty-table\n    docker run -dit --name tty-table-in-browser -p 8070:80 -v \"$PWD\":/usr/local/apache2/htdocs/ httpd:2.4\n    ```\n\n- [live demo (chrome only): jsfiddle](https://jsfiddle.net/nb14eyav/)\n- [live demo (chrome only): plnkr](https://plnkr.co/edit/iQn9xn5yCY4NUkXRF87o?p=preview)\n- [source: examples/browser-example.html](examples/browser-example.html)\n\n![Browser Console Example](https://user-images.githubusercontent.com/7478359/74614563-cbcaff00-50e6-11ea-9101-5457497696b8.jpg \"tty-table in the browser console\") \n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## API Reference \n\u003c!--API-REF--\u003e\n\n\u003ca name=\"new_Table_new\"\u003e\u003c/a\u003e\n### Table(header ```array```, rows ```array```, options ```object```)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| [header](#header_options) | \u003ccode\u003earray\u003c/code\u003e | Per-column configuration. An array of objects, one object for each column. Each object contains properties you can use to configure that particular column. [See available properties](#header_options) |\n| [rows](#rows_examples) | \u003ccode\u003earray\u003c/code\u003e | Your data. An array of arrays or objects. [See examples](#rows_examples) |\n| [options](#options_properties) | \u003ccode\u003eobject\u003c/code\u003e | Global table configuration. [See available properties](#options_properties) |\n\n\n\u003cbr/\u003e\n\u003ca name=\"header_options\"\u003e\u003c/a\u003e\n\n#### header ```array of objects```\n\n| Param | Type | Description |\n| --- | --- | --- |\n| alias | \u003ccode\u003estring\u003c/code\u003e | Text to display in column header cell |\n| align | \u003ccode\u003estring\u003c/code\u003e | default: \"center\" |\n| color | \u003ccode\u003estring\u003c/code\u003e | default: terminal default color |\n| footerAlign | \u003ccode\u003estring\u003c/code\u003e | default: \"center\" |\n| footerColor | \u003ccode\u003estring\u003c/code\u003e | default: terminal default color |\n| formatter | \u003ccode\u003efunction(cellValue, columnIndex, rowIndex, rowData, inputData\u003c/code\u003e | Runs a callback on each cell value in the parent column. \u003cbr/\u003ePlease note that fat arrow functions `() =\u003e {}` don't support scope overrides, and this feature won't work correctly within them.  |\n| @formatter configure | \u003ccode\u003efunction(object)\u003c/code\u003e | Configure cell properties. For example: \u003cbr/\u003e`this.configure({ truncate: false, align: \"left\" })` [More here](https://github.com/tecfu/tty-table/blob/master/examples/truncated-lines.js#L100-L110). |\n| @formatter resetStyle | \u003ccode\u003efunction(cellValue)\u003c/code\u003e | Removes ANSI escape sequences. For example: \u003cbr/\u003e`this.resetStyle(\"\u001b[32m\u001b myText\u001b\u001b[39m\") // \"myText\"`\u003cbr/\u003e |\n| @formatter style | \u003ccode\u003efunction(cellValue, effect)\u003c/code\u003e | Style cell value. For example: \u003cbr/\u003e`this.style(\"mytext\", \"bold\", \"green\", \"underline\")`\u003cbr/\u003eFor a full list of options in the terminal: [chalk](https://github.com/chalk/chalk). For a full list of options in the browser: [kleur](https://github.com/lukeed/kleur)|\n| headerAlign | \u003ccode\u003estring\u003c/code\u003e | default: \"center\" |\n| headerColor | \u003ccode\u003estring\u003c/code\u003e | default: terminal's default color |\n| marginLeft | \u003ccode\u003einteger\u003c/code\u003e | default: 0 |\n| marginTop | \u003ccode\u003einteger\u003c/code\u003e | default: 0 |\n| paddingBottom | \u003ccode\u003einteger\u003c/code\u003e | default: 0 |\n| paddingLeft | \u003ccode\u003einteger\u003c/code\u003e | default: 1 |\n| paddingRight | \u003ccode\u003einteger\u003c/code\u003e | default: 1 |\n| paddingTop | \u003ccode\u003einteger\u003c/code\u003e | default: 0 |\n| value | \u003ccode\u003estring\u003c/code\u003e | Name of the property to display in each cell when data passed as an array of objects |\n| width | \u003ccode\u003estring\u003c/code\u003e \\|\\| \u003ccode\u003einteger\u003c/code\u003e | default: \"auto\" \u003cbr/\u003e Can be a percentage of table width i.e. \"20%\" or a fixed number of columns i.e. \"20\". \u003cbr/\u003e When set to the default (\"auto\"), the column widths are made proportionate by the longest value in each column. \u003cbr/\u003e Note: Percentage columns and fixed value colums not intended to be mixed in the same table.|\n\n**Example**\n\n```js\nlet header = [{\n  value: \"item\",\n  headerColor: \"cyan\",\n  color: \"white\",\n  align: \"left\",\n  width: 20\n},\n{\n  value: \"price\",\n  color: \"red\",\n  width: 10,\n  formatter: function (value) {\n    let str = `$${value.toFixed(2)}`\n    return (value \u003e 5) ? this.style(str, \"green\", \"bold\") : \n      this.style(str, \"red\", \"underline\")\n  }\n}]\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003ca name=\"rows_examples\"\u003e\u003c/a\u003e\n\n#### rows ```array```\n\n**Example**\n- each row an array\n```js\nconst rows = [\n  [\"hamburger\",2.50],\n]\n```\n- each row an object\n```js\nconst rows = [\n  {\n    item: \"hamburger\",\n    price: 2.50\n  }\n]\n```\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003ca name=\"footer_example\"\u003e\u003c/a\u003e\n\n#### footer ```array```\n- Footer is optional\n\n**Example**\n```js\nconst footer = [\n  \"TOTAL\",\n  function (cellValue, columnIndex, rowIndex, rowData) {\n    let total = rowData.reduce((prev, curr) =\u003e {\n      return prev + curr[1]\n    }, 0)\n    .toFixed(2)\n\n    return this.style(`$${total}`, \"italic\")\n  }\n]\n``` \n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003ca name=\"options_properties\"\u003e\u003c/a\u003e\n\n#### options ```object```\n\n| Param | Type | Description |\n| --- | --- | --- |\n| borderStyle | \u003ccode\u003estring\u003c/code\u003e | default: \"solid\". \u003cbr/\u003e options: \"solid\", \"dashed\", \"none\" |\n| borderColor | \u003ccode\u003estring\u003c/code\u003e | default: terminal default color |\n| color | \u003ccode\u003estring\u003c/code\u003e | default: terminal default color |\n| compact | \u003ccode\u003eboolean\u003c/code\u003e | default: false \u003cbr/\u003e Removes horizontal borders when true. |\n| defaultErrorValue | \u003ccode\u003emixed\u003c/code\u003e | default: '�' |\n| defaultValue | \u003ccode\u003emixed\u003c/code\u003e | default: '?' |\n| errorOnNull | \u003ccode\u003eboolean\u003c/code\u003e | default: false |\n| truncate | \u003ccode\u003emixed\u003c/code\u003e | default: false \u003cbr/\u003e When this property is set to a string, cell contents will be truncated by that string instead of wrapped when they extend beyond of the width of the cell.  \u003cbr/\u003e For example if: \u003cbr/\u003e \u003ccode\u003e\"truncate\":\"...\"\u003c/code\u003e \u003cbr/\u003e the cell will be truncated with \"...\" \u003cbr/\u003e Note: tty-table wraps overflowing cell text into multiple lines by default, so you would likely only utilize `truncate` for extremely long values. |\n| width | \u003ccode\u003estring\u003c/code\u003e | default: \"100%\" \u003cbr/\u003e Width of the table. Can be a percentage of i.e. \"50%\" or a fixed number of columns in the terminal viewport i.e. \"100\". \u003cbr/\u003e Note: When you use a percentage, your table will be \"responsive\".|\n\n\n**Example**\n```js\nconst options = {\n  borderStyle: \"solid\",\n  borderColor: \"blue\",\n  headerAlign: \"center\",\n  align: \"left\",\n  color: \"white\",\n  truncate: \"...\",\n  width: \"90%\"\n}\n```\n\n\u003cbr/\u003e\n\n### Table.render() ⇒ \u003ccode\u003eString\u003c/code\u003e\n\u003ca name=\"Table.tableObject.render\"\u003e\u003c/a\u003e\n\nAdd method to render table to a string\n\n**Example**  \n```js\nconst out = Table(header,rows,options).render()\nconsole.log(out); //prints output\n```\n\n\u003c!--END-API-REF--\u003e\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## Installation\n\n- [Terminal](docs/terminal.md):\n\n```sh\n$ npm install tty-table -g\n```\n\n- Node Module\n\n```sh\n$ npm install tty-table\n```\n\n- Browser\n\n```js\nimport Table from 'https://cdn.jsdelivr.net/gh/tecfu/tty-table/dist/tty-table.esm.js'\nlet Table = require('tty-table')   // https://cdn.jsdelivr.net/gh/tecfu/tty-table/dist/tty-table.cjs.js\nlet Table = TTY_Table;             // https://cdn.jsdelivr.net/gh/tecfu/tty-table/dist/tty-table.umd.js\n```\n\n## Version Compatibility\n\n| Node Version   |   tty-table Version  |\n| -------------- | ------------------|\n| 8              | \u003e= 2.0            |\n| 0.11           | \u003e= 0.0            |\n\n## Running tests\n\n```sh\n$ npm test\n```\n\n```sh\n$ npm run coverage\n```\n\n## Saving the output of new unit tests \n\n```sh\n$ npm run save-tests\n```\n\n## Dev Tips\n\n- To generate vim tags (make sure [jsctags](https://github.com/ramitos/jsctags) is installed globally)\n\n```sh\n$ npm run tags\n```\n\n- To generate vim tags on file save \n\n```sh\n$ npm run watch-tags\n```\n\n## Pull Requests\n\nPull requests are encouraged!\n\n- Please remember to add a unit test when necessary\n- Please format your commit messages according to the [\"Conventional Commits\"](https://www.conventionalcommits.org/en/v1.0.0/) specification\n\nIf you aren't familiar with Conventional Commits, here's a good [article on the topic](https://dev.to/maniflames/how-conventional-commits-improved-my-git-skills-1jfk)\n\nTL/DR:\n\n- feat: a feature that is visible for end users.\n- fix: a bugfix that is visible for end users.\n- chore: a change that doesn't impact end users (e.g. chances to CI pipeline)\n- docs: a change in the README or documentation\n- refactor: a change in production code focused on readability, style and/or performance.\n\n\n## [Packaging as a distributable](packaging.md)\n\n\n## License\n\n[MIT License](https://opensource.org/licenses/MIT)\n\nCopyright 2015-2020, Tecfu. \n","funding_links":[],"categories":["JavaScript","nodejs"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftecfu%2Ftty-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftecfu%2Ftty-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftecfu%2Ftty-table/lists"}