https://github.com/hustcc/word-table
:black_medium_square: a simple javascript (browserjs / nodejs) library for drawing tables in the terminal / console, unicode supported.
https://github.com/hustcc/word-table
ascii ascii-table draw-table javascript nodejs word-table
Last synced: about 1 month ago
JSON representation
:black_medium_square: a simple javascript (browserjs / nodejs) library for drawing tables in the terminal / console, unicode supported.
- Host: GitHub
- URL: https://github.com/hustcc/word-table
- Owner: hustcc
- License: mit
- Created: 2016-10-14T07:10:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-19T01:17:43.000Z (almost 8 years ago)
- Last Synced: 2024-10-17T16:04:03.358Z (6 months ago)
- Topics: ascii, ascii-table, draw-table, javascript, nodejs, word-table
- Language: JavaScript
- Homepage: http://git.hust.cc/word-table
- Size: 28.3 KB
- Stars: 59
- Watchers: 5
- Forks: 14
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# word-table
> **word-table** is a simple javascript (browserjs / nodejs) library for drawing ascii tables in the `terminal` / `console`. Based on [word-width](https://github.com/hustcc/word-width).
[](https://travis-ci.org/hustcc/word-table) [](https://coveralls.io/github/hustcc/word-table?branch=master) [](https://www.npmjs.com/package/word-table) [](https://www.npmjs.com/package/word-table) [](https://www.npmjs.com/package/word-table)

# 1. Install & Import
> **npm install word-table**
- Import it with `script` tag in HTML.
```js
```
- Import it with `require`.
```js
var WordTable = require('word-table');
//or
import WordTable from 'word-table';
```# 2. Usage & API
See a demo firstly:
```js
var header = ['id', 'name', 'birthday'];
var body = [
['#1', '王小为', '1992-08-01', '备注:hustcc'],
['#2', '小泥巴', '1992-09-20'],
['#3', '佚名', '保密']
];// basic usage
var wt = new WordTable(header, body);
console.log(wt.string());
```The API is so simple that documents are not needed.
```js
wt.setHeader(['id', 'name', 'birthday']);
wt.appendBody(['#3', '佚名', '保密']);
wt.setBody([['#4', '在线工具', '保密', 'atool.org']]);
wt.array();
wt.string();
wt.reset();
```Detail usage and demo code, can see [here](tests/test.js), and run `npm test` can see the output.
The api are all chainable method, e.g.
```js
var wt = new WordTable();
wt.reset()
.setHeader(['id', 'name', 'birthday'])
.appendBody(['#3', '佚名', '保密']);
var str = wt.string();
```# 3. Test
> npm install
>
> npm run build
>
> npm testOr you can open the [website](http://git.hust.cc/word-table/), then test it in `Console [F12]`.
# 4. LICENSE
MIT@[hustcc](https://github.com/hustcc).