# term-grid

> Create grid in the terminal, config color,width,align for each column

Latest version **0.1.8** (published 2016-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install term-grid
pnpm add term-grid
yarn add term-grid
bun add term-grid
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2016-03-22 |
| First published | 2014-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | mangix |
| Maintainers | mangix |
| Keywords | terminal, grid |

## Links

- npm: https://www.npmjs.com/package/term-grid
- Repository: https://github.com/mangix/term-grid
- Issues: https://github.com/mangix/term-grid/issues
- npm.io page: https://npm.io/package/term-grid

## Dependencies (1)

- [strip-ansi](https://npm.io/package/strip-ansi.md) ^2.0.1

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.8 (latest) — 2016-03-22
- 0.1.7 — 2014-12-16
- 0.1.6 — 2014-12-16
- 0.1.5 — 2014-12-15
- 0.1.4 — 2014-12-15
- 0.1.3 — 2014-12-15
- 0.1.2 — 2014-12-15
- 0.1.1 — 2014-12-14
- 0.1.0 — 2014-12-14

## README

# term-grid


term-grid create grid in the terminal, you can config color,width,align for each column.


## Install
  ```
  $ npm install term-grid
  ```

## Usage
```js
  var Grid = require("term-grid");
  var grid = new Grid([["Name","Age","City"],["Allan",20,"New York"],["Jack",30,"London"]]);
  grid.setColor(0,"green");
  grid.setWidth(1,10);
  grid.setAlign(2,"right");
  grid.draw();
  
```
![rect](https://raw.githubusercontent.com/mangix/term-grid/master/grid.png)

## API
### - setWidth(column,width)
set width for column .  width 0(and is default) means auto 
```js
  grid.setWidth(0,10); //set the first column with width 10
  grid.setWidth([10,20,5,10]); //set each column
```

### - setColor([column,]color)
set color for column.

if the first param `column` not set, all column will be set to `color` .

color could be a string or a function returns string.

colors string support : `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white`
```js
  grid.setColor(0,"red"); //set the first column red
  grid.setColor(["red","yellow","green"]); //set each column
  set the second column data `red` when it's greater than 10
  grid.setColor(1,function(content,row,column){
    if(content > 10){
        return "red";
    }
  });
  //equals setColor("red")
  grid.setColor(function(content,row,column){
     return "red";
  });
```
Notice that colors are managed group by column , and each column could has only one color ever a string or a function.

setColor to the same column will overwrite the color set before.

setColor without param `column` will overwrite all column color.



### - setAlign(column,width)
set width for column , `left` `right`,`center`  and `left` by default.
```js
  grid.setAlign(0,"center"); //set the first column align center
  grid.setAlign(['left','center' ,'left','right']); //set each column
```

### - draw()
draw grid to the terminal


## output grid to file
Default output stream is `process.stdout`. You can set 'grid.stream' to other  [Stream](http://nodejs.org/api/stream.html#stream_class_stream_writable);
```js
grid.stream = require("fs").createWriteStream("grid.txt");
grid.draw();
```

## license
MIT

---
_Source: https://npm.io/package/term-grid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
