{"id":15434275,"url":"https://github.com/cenfun/console-grid","last_synced_at":"2025-04-19T18:09:20.516Z","repository":{"id":56789246,"uuid":"165461669","full_name":"cenfun/console-grid","owner":"cenfun","description":"Console log a grid with tree style rows","archived":false,"fork":false,"pushed_at":"2025-01-07T14:11:33.000Z","size":329,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T10:13:26.288Z","etag":null,"topics":["columns","console","formatters","grid","log","rows","sort","style","subs","tree"],"latest_commit_sha":null,"homepage":"","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/cenfun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.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":"2019-01-13T03:29:24.000Z","updated_at":"2025-01-07T14:13:58.000Z","dependencies_parsed_at":"2024-02-29T13:48:02.599Z","dependency_job_id":"b5476f86-2879-4031-8f4d-ba757ecd2cac","html_url":"https://github.com/cenfun/console-grid","commit_stats":{"total_commits":59,"total_committers":3,"mean_commits":"19.666666666666668","dds":"0.30508474576271183","last_synced_commit":"206a1b56b0009ed6aaee9d72db354cfdf1348857"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fconsole-grid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fconsole-grid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fconsole-grid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cenfun%2Fconsole-grid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cenfun","download_url":"https://codeload.github.com/cenfun/console-grid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249758767,"owners_count":21321591,"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":["columns","console","formatters","grid","log","rows","sort","style","subs","tree"],"created_at":"2024-10-01T18:38:36.952Z","updated_at":"2025-04-19T18:09:20.499Z","avatar_url":"https://github.com/cenfun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# console-grid\n\n![](https://img.shields.io/npm/v/console-grid.svg)\n![](https://img.shields.io/npm/dt/console-grid.svg)\n\n## Features\n* Console log a grid \n* Support tree style rows\n* Custom cell formatter\n* Column align/sorting\n* Multiple lines header\n* Support colorful cells\n\n## Install\n```\nnpm i console-grid\n```\n\n## Usage\n\n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"columns\": [\"\", \"Name\", \"Value\"],\n    \"rows\": [\n        [1, \"Tom\", \"Value 1\"],\n        [2, \"Jerry\", \"Value 2\"]\n    ]\n});  \n\n┌───┬───────┬─────────┐\n│   │ Name  │ Value   │\n├───┼───────┼─────────┤\n│ 1 │ Tom   │ Value 1 │\n│ 2 │ Jerry │ Value 2 │\n└───┴───────┴─────────┘  \n```  \n## Without header:  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"options\": {\n        \"headerVisible\": false\n    },\n    \"columns\": [\"\", \"Name\", \"Value\"],\n    \"rows\": [\n        [1, \"Tom\", \"Value 1\"],\n        [2, \"Jerry\", \"Value 2\"]\n    ]\n});  \n\n┌───┬───────┬─────────┐\n│ 1 │ Tom   │ Value 1 │\n│ 2 │ Jerry │ Value 2 │\n└───┴───────┴─────────┘  \n```  \n## With column minWidth and maxWidth (Multiple Line Header):  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"columns\": [\"\", {\n        \"name\": \"Name\",\n        \"minWidth\": 15\n    }, {\n        \"name\": \"Value\",\n        \"maxWidth\": 20\n    }, {\n        \"name\": \"Multiple Line Header\",\n        \"maxWidth\": 15\n    }],\n    \"rows\": [\n        [1, \"Hello\", \"Long Text Value\", \"Long Text Value\"],\n        [2, \"Hello There\", \"Long Text Value Long Text Value\", \"Long Text Value Long Text Value\"]\n    ]\n});  \n\n┌───┬─────────────────┬──────────────────────┬─────────────────┐\n│   │                 │                      │ Multiple Line   │\n│   │ Name            │ Value                │ Header          │\n├───┼─────────────────┼──────────────────────┼─────────────────┤\n│ 1 │ Hello           │ Long Text Value      │ Long Text Value │\n│ 2 │ Hello There     │ Long Text Value L... │ Long Text Va... │\n└───┴─────────────────┴──────────────────────┴─────────────────┘  \n```  \n## With column align and padding:  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"options\": {\n        \"padding\": 2\n    },\n    \"columns\": [{\n        \"id\": \"default\",\n        \"name\": \"Default\"\n    }, {\n        \"id\": \"left\",\n        \"name\": \"Left\",\n        \"align\": \"left\"\n    }, {\n        \"id\": \"center\",\n        \"name\": \"Center\",\n        \"align\": \"center\"\n    }, {\n        \"id\": \"right\",\n        \"name\": \"Right\",\n        \"align\": \"right\"\n    }, {\n        \"id\": \"right\",\n        \"name\": \"Multiple Line Right\",\n        \"maxWidth\": 12,\n        \"align\": \"right\"\n    }],\n    \"rows\": [{\n        \"default\": \"Cell\",\n        \"left\": \"Markdown\",\n        \"center\": \"Start\",\n        \"right\": \"123.0\"\n    }, {\n        \"default\": \"Content\",\n        \"left\": \"Grid\",\n        \"center\": \"Complete\",\n        \"right\": \"8.1\"\n    }]\n});  \n\n┌───────────┬────────────┬────────────┬─────────┬────────────────┐\n│           │            │            │         │      Multiple  │\n│  Default  │  Left      │   Center   │  Right  │    Line Right  │\n├───────────┼────────────┼────────────┼─────────┼────────────────┤\n│  Cell     │  Markdown  │    Start   │  123.0  │         123.0  │\n│  Content  │  Grid      │  Complete  │    8.1  │           8.1  │\n└───────────┴────────────┴────────────┴─────────┴────────────────┘  \n```  \n## With tree rows (nullPlaceholder/number align and formatter):  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"columns\": [{\n        \"id\": \"name\",\n        \"name\": \"Name\",\n        \"type\": \"string\",\n        \"maxWidth\": 30\n    }, {\n        \"id\": \"value\",\n        \"name\": \"Value\",\n        \"type\": \"string\",\n        \"maxWidth\": 7\n    }, {\n        \"id\": \"null\",\n        \"name\": \"Null\"\n    }, {\n        \"id\": \"number\",\n        \"type\": \"number\",\n        \"name\": \"Number\",\n        \"maxWidth\": 12\n    }],\n    \"rows\": [{\n        \"name\": \"Row 1\",\n        \"value\": \"1\",\n        \"number\": 1\n    }, {\n        \"name\": \"Row Name\",\n        \"value\": \"2\",\n        \"number\": 2\n    }, {\n        \"name\": \"Row Long Name Long Name Long Name\",\n        \"value\": \"3\",\n        \"number\": 3\n    }, {\n        \"name\": \"Group\",\n        \"value\": \"4\",\n        \"number\": 4,\n        \"subs\": [{\n            \"name\": \"Sub Group 1\",\n            \"value\": \"5\",\n            \"number\": 5,\n            \"subs\": [{\n                \"name\": \"Sub Group 1 Sub Row 1\",\n                \"value\": \"6\",\n                \"number\": 6\n            }, {\n                \"name\": \"Sub Group 1 Sub Row 2\",\n                \"value\": \"7\",\n                \"number\": 7\n            }]\n        }, {\n            \"name\": \"Sub Row 1\",\n            \"value\": \"8\",\n            \"number\": 8\n        }, {\n            \"name\": \"Sub Row 2\",\n            \"value\": \"9\",\n            \"number\": 9\n        }]\n    }]\n});  \n\n┌────────────────────────────────┬───────┬──────┬────────┐\n│ Name                           │ Value │ Null │ Number │\n├────────────────────────────────┼───────┼──────┼────────┤\n│ Row 1                          │ 1     │ -    │   1.00 │\n│ Row Name                       │ 2     │ -    │   2.00 │\n│ Row Long Name Long Name Lon... │ 3     │ -    │   3.00 │\n│ Group                          │ 4     │ -    │   4.00 │\n│ ├ Sub Group 1                  │ 5     │ -    │   5.00 │\n│ │ ├ Sub Group 1 Sub Row 1      │ 6     │ -    │   6.00 │\n│ │ └ Sub Group 1 Sub Row 2      │ 7     │ -    │   7.00 │\n│ ├ Sub Row 1                    │ 8     │ -    │   8.00 │\n│ └ Sub Row 2                    │ 9     │ -    │   9.00 │\n└────────────────────────────────┴───────┴──────┴────────┘  \n```  \n## With inner border:  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"columns\": [{\n        \"id\": \"name\",\n        \"name\": \"Name\"\n    }, {\n        \"id\": \"value\",\n        \"name\": \"Value\"\n    }],\n    \"rows\": [{\n        \"name\": \"Total\",\n        \"value\": 80\n    }, {\n        \"innerBorder\": true\n    }, {\n        \"name\": \"Item 1\",\n        \"value\": 30\n    }, {\n        \"name\": \"Item 2\",\n        \"value\": 50,\n        \"subs\": [{\n            \"name\": \"Sub 21\"\n        }, {\n            \"name\": \"\"\n        }, {\n            \"name\": \"Sub 22\"\n        }]\n    }]\n});  \n\n┌──────────┬───────┐\n│ Name     │ Value │\n├──────────┼───────┤\n│ Total    │ 80    │\n├──────────┼───────┤\n│ Item 1   │ 30    │\n│ Item 2   │ 50    │\n│ ├ Sub 21 │ -     │\n│ │        │ -     │\n│ └ Sub 22 │ -     │\n└──────────┴───────┘  \n```  \n## With column sorting:  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"options\": {\n        \"sortField\": \"value\",\n        \"sortAsc\": false\n    },\n    \"columns\": [{\n        \"id\": \"name\",\n        \"name\": \"Name\"\n    }, {\n        \"id\": \"value\",\n        \"name\": \"Value\",\n        \"type\": \"number\"\n    }],\n    \"rows\": [{\n        \"name\": \"Item 1\",\n        \"value\": 80\n    }, {\n        \"name\": \"Item 2\",\n        \"value\": 30\n    }, {\n        \"name\": \"Item 3\",\n        \"value\": 50\n    }]\n});  \n\n┌────────┬────────┐\n│ Name   │ Value* │\n├────────┼────────┤\n│ Item 1 │     80 │\n│ Item 3 │     50 │\n│ Item 2 │     30 │\n└────────┴────────┘  \n```  \n## With color (using [eight-colors](https://github.com/cenfun/eight-colors)):  \n```js  \nconst CG = require(\"console-grid\");\nconst EC = require(\"eight-colors\");\nconst data = {\n    columns: ['Name', EC.cyan('Color Text'), EC.bg.cyan('Color Background')],\n    rows: [\n        ['Red', EC.red('red text'), EC.bg.red('red bg')],\n        ['Green', EC.green('green text'), EC.bg.green('green text')]\n    ]\n};\nCG(data);  \n```  \n![](/scripts/screenshots.png)  \n```js  \n// silent output and remove color\ndata.options = {\n    silent: true\n};\nconst lines = CG(data);\nconst withoutColor = EC.remove(lines.join(os.EOL));\nconsole.log(withoutColor);  \n\n┌───────┬────────────┬──────────────────┐\n│ Name  │ Color Text │ Color Background │\n├───────┼────────────┼──────────────────┤\n│ Red   │ red text   │ red bg           │\n│ Green │ green text │ green text       │\n└───────┴────────────┴──────────────────┘  \n```  \n## With CSV (using [papaparse](https://github.com/mholt/PapaParse)):  \n```js  \nconst CG = require(\"console-grid\");\nconst Papa = require(\"papaparse\");\nconst csvString = `Column 1,Column 2,Column 3,Column 4\n1-1,1-2,1-3,1-4\n2-1,2-2,2-3,2-4\n3-1,3-2,3-3,3-4\n4,5,6,7`;\nconst json = Papa.parse(csvString);\nconst data = {\n    columns: json.data.shift(),\n    rows: json.data\n};\nCG(data);  \n\n┌──────────┬──────────┬──────────┬──────────┐\n│ Column 1 │ Column 2 │ Column 3 │ Column 4 │\n├──────────┼──────────┼──────────┼──────────┤\n│ 1-1      │ 1-2      │ 1-3      │ 1-4      │\n│ 2-1      │ 2-2      │ 2-3      │ 2-4      │\n│ 3-1      │ 3-2      │ 3-3      │ 3-4      │\n│ 4        │ 5        │ 6        │ 7        │\n└──────────┴──────────┴──────────┴──────────┘  \n```  \n## With special character:  \n- Unresolved: some special characters has unexpected width, especially on different output terminals (depends on fonts)  \n```js  \nconst CG = require(\"console-grid\");\nCG({\n    \"columns\": [\"Special\", \"Character\"],\n    \"rows\": [\n        [\"Chinese,中文\", \"12【标，点。】\"],\n        [\"あいアイサてつろ\", \"☆√✔×✘❤♬\"],\n        [\"㈀ㅏ㉡ㅎㅉㅃㅈㅂ\", \"①⑵⒊Ⅳ❺ʊəts\"],\n        [\"汉字繁體\", \"АБВДшщыф\"],\n        [\"Emoji👋👩⌚✅\", \"↑↓▲▼○●♡♥\"]\n    ]\n});  \n\n┌───────────────────┬──────────────────┐\n│ Special           │ Character        │\n├───────────────────┼──────────────────┤\n│ Chinese,中文      │ 12【标，点。】   │\n│ あいアイサてつろ  │ ☆√✔×✘❤♬   │\n│ ㈀ㅏ㉡ㅎㅉㅃㅈㅂ  │ ①⑵⒊Ⅳ❺ʊəts │\n│ 汉字繁體          │ АБВДшщыф │\n│ Emoji👋👩⌚✅ │ ↑↓▲▼○●♡♥ │\n└───────────────────┴──────────────────┘  \n```  \n## With custom getCharLength (using [eastasianwidth](https://github.com/komagata/eastasianwidth)):  \n- Unresolved: still not perfect in special character width  \n```js  \nconst CG = require(\"console-grid\");\nconst eaw = require(\"eastasianwidth\");\nCG({\n    options: {\n        getCharLength: (char) =\u003e {\n            return eaw.length(char);\n        }\n    },\n    columns: [\"Special\", \"Character\"],\n    rows: [\n        [\"Chinese,中文\", \"12【标，点。】\"],\n        [\"あいアイサてつろ\", \"☆√✔×✘❤♬\"],\n        [\"㈀ㅏ㉡ㅎㅉㅃㅈㅂ\", \"①⑵⒊Ⅳ❺ʊəts\"],\n        [\"汉字繁體\", \"АБВДшщыф\"],\n        [\"Emoji👋👩⌚✅\", \"↑↓▲▼○●♡♥\"]\n    ]\n});  \n\n┌──────────────────┬──────────────────┐\n│ Special          │ Character        │\n├──────────────────┼──────────────────┤\n│ Chinese,中文     │ 12【标，点。】   │\n│ あいアイサてつろ │ ☆√✔×✘❤♬      │\n│ ㈀ㅏ㉡ㅎㅉㅃㅈㅂ │ ①⑵⒊Ⅳ❺ʊəts   │\n│ 汉字繁體         │ АБВДшщыф │\n│ Emoji👋👩⌚✅        │ ↑↓▲▼○●♡♥ │\n└──────────────────┴──────────────────┘  \n``` \n\n## Data Format Definition: [CGDF](https://github.com/cenfun/cgdf)\n```js\n{\n    options: Object, //define grid level options\n    columns: Array, //define column list and header\n    rows: Array //define row list\n}\n```\n\n## Default Options\n```js\n{\n    silent: false,\n    headerVisible: false,\n\n    padding: 1,\n    defaultMinWidth: 1,\n    defaultMaxWidth: 50,\n\n    sortField: '',\n    sortAsc: false,\n    sortIcon: '*',\n\n    treeId: 'name',\n    treeIcon: '├ ',\n    treeLink: '│ ',\n    treeLast: '└ ',\n    treeIndent: '  ',\n\n    nullPlaceholder: '-',\n\n    //border definition:\n    //H: horizontal, V: vertical\n    //T: top, B: bottom, L: left, R: right, C: center\n    borderH: '─',\n    borderV: '│',\n    borderTL: '┌',\n    borderTC: '┬',\n    borderTR: '┐',\n    borderCL: '├',\n    borderCC: '┼',\n    borderCR: '┤',\n    borderBL: '└',\n    borderBC: '┴',\n    borderBR: '┘',\n\n    getCharLength: defaultGetCharLength\n    \n}\n```\n\n## Column Properties\n```js\n{\n    id: String,\n    name: String,\n    type: String, //string, number\n    align : String, //left(default), center, right\n    minWidth: Number,\n    maxWidth: Number,\n    formatter: Function //custom cell formatter\n}\n```\n\n## Row Properties\n```js\n{\n    //column id key: cell value\n    innerBorder: Boolean,\n    subs: Array //sub rows\n}\n```\n\n## CHANGELOG\n[CHANGELOG.md](CHANGELOG.md)\n\n\n## Markdown Grid\n[markdown-grid](https://github.com/cenfun/markdown-grid) - Markdown Grid Generator","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenfun%2Fconsole-grid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcenfun%2Fconsole-grid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenfun%2Fconsole-grid/lists"}