Skip to content

Commit

Permalink
Merge d2c93a3 into decdee1
Browse files Browse the repository at this point in the history
  • Loading branch information
takamin committed May 3, 2020
2 parents decdee1 + d2c93a3 commit 0d9fcd0
Showing 1 changed file with 36 additions and 46 deletions.
82 changes: 36 additions & 46 deletions README.md
Expand Up @@ -72,13 +72,14 @@ In following example, `$` means root oject.

![listit sample/planets.json output](https://takamin.github.io/list-it/images//sample-listit-cli-command-output.png)

Using the exported ListIt class
-------------------------------

PROGRAMMING SAMPLE
------------------
### PROGRAMMING SAMPLE

__[sample/japanese-food.js](sample/japanese-food.js)__

```
```javascript
var ListIt = require("list-it");
var buf = new ListIt();
buf.setColumnWidth(1, 5);
Expand Down Expand Up @@ -106,7 +107,7 @@ console.log(

outputs:

```
```bash
$ node sample/japanese-food.js
1 Sushi vinegared rice Healthy
2 Yakin Grilled meat on Juicy
Expand All @@ -115,11 +116,11 @@ $ node sample/japanese-food.js
5 Sashi Very fresh slic Try it
```

### autoAlign and setHeaderRoe
#### autoAlign and setHeaderRow

__[sample/planets.js](sample/planets.js)__

```
```javascript
const ListIt = require("list-it");
const listit = new ListIt({
autoAlign : true,
Expand Down Expand Up @@ -148,7 +149,7 @@ console.log(listit

outputs:

```
```bash
$ node sample/planets.js
NAME Mass(10^24kg) Dia(km) Dens(kg/m3) Grav(m/s2) EscV(km/s) Rot(hours)
------- ------------- ------- ----------- ---------- ---------- ----------
Expand All @@ -164,11 +165,12 @@ NEPTUNE 102.0 49528 1638 11.0 23.5 16.1
PLUTO 0.0146 2370 2095 0.7 1.3 -153.3
```

### Object Array
#### Object Array


__[sample/planets-obj.js](sample/planets-obj.js)__
```

```javascript
const ListIt = require("../index.js");
const list = new ListIt({
headerBold: true,
Expand Down Expand Up @@ -205,11 +207,11 @@ outputs:
![sample/planets-obj.js outputs](https://takamin.github.io/list-it/images/sample-planets-obj-js-output.png)


### East asian characters
#### East asian characters

__[sample/japanese-food-jp.js](sample/japanese-food-jp.js)__

```
```javascript
var ListIt = require("list-it");
var buf = new ListIt();
console.log(
Expand All @@ -234,7 +236,7 @@ console.log(

outputs:

```
```bash
$ node sample/japanese-food-jp.js
1 寿司 酢とご飯とシーフード 健康的だ
2 焼肉 日本のグリルされたお肉 ジューシー
Expand All @@ -244,15 +246,16 @@ $ node sample/japanese-food-jp.js
```



Class ListIt
API Reference
------------

### CONSTRUCTOR
### Class ListIt

#### CONSTRUCTOR

* __ListIt(options)__

### OPTIONS
#### OPTIONS

* __autoAlign__ - Specifies the number data alignment.
* __columnWidth__ - Initializes the text max length for all columns.
Expand All @@ -264,7 +267,7 @@ Class ListIt
* __headerColor__ - Set color to the header text.
* __headerUnderline__ - Add underline to the header text.

### METHODS
#### METHODS

* __setColumnWidth__ - Sets a text max length to a column.
* __setColumnWidthAll__ - Sets text max length to all columns.
Expand All @@ -273,8 +276,7 @@ Class ListIt
* __nl__ - New line
* __toString__ - Format a table

Constructor ListIt(opt)
-----------------------
### Constructor ListIt(opt)

__`const listit = new ListIt(opt)`__

Expand All @@ -284,16 +286,14 @@ The instance has current row that is a position for the columns to be added.

To add a cell, use 'd' method. Check the samples above.

OPTION.autoAlign
----------------
### OPTION.autoAlign

__`autoAlign:boolean` (Default: `true`)__

When this is set true, the data in cell will be aligned in Automatic depending on its type.
The number will be aligned to the right taking account of its decimal point.

OPTION.columnWidth
------------------
### OPTION.columnWidth

__`columnWidth:Array<number>|number|null` (Default: `null`)__

Expand All @@ -305,8 +305,7 @@ A `null` as the element value means that width will not be specified.
* __Set a Width For All Columns__ - If a single number is specified for this option, It will set to all columns.
And also when the value is null, column width is not declared at all.

OPTION.header
-------------
### OPTION.header

__`header:Array<any>|null` (Default: `null`)__

Expand All @@ -319,8 +318,7 @@ This header-auto-creation feature will be activated when following two condition
* One or more header-relating-options except for `header` are set.


OPTION.headerBold
-----------------
### OPTION.headerBold

__`headerBold:boolean` (Default: `false`)__

Expand All @@ -329,8 +327,7 @@ But, actual appearance would be dependent on the terminal.

If the header does not exists, no effect is appeared.

OPTION.headerColor
------------------
### OPTION.headerColor

__`headerColor:string|null` (Default: `null`)__

Expand Down Expand Up @@ -360,17 +357,15 @@ Available color names:
* "brightWhite"


OPTION.headerUnderline
----------------------
### OPTION.headerUnderline

__`headerUnderline:boolean` (Default: `false`)__

When this option is true, an underline will be drawn for the header text.

If the header does not exists, no effect is appeared.

ListIt#setColumnWidth
----------------------------------------------------------
### ListIt#setColumnWidth

__`setColumnWidth(indexOfColumns:number, width:number)`__

Expand All @@ -391,8 +386,7 @@ RETURN VALUE:

This method returns `this` instance to chain the next method call.

ListIt#setColumnWidthAll
--------------------------------------------------------------------
### ListIt#setColumnWidthAll

__`setColumnWidthAll(widthForAll:Array<number|null>|number|null)`__

Expand All @@ -406,17 +400,15 @@ RETURN VALUE:

This method returns `this` instance to chain the next method call.

ListIt#setHeaderRow
-------------------
### ListIt#setHeaderRow

__`setHeaderRow(header:Array<any>|null)`__

With this method, set the column header row.
For the parameter, it is same as OPTION.header.
If null is specified, the header would be removed.

ListIt#d
-----------------------------
### ListIt#d

__`d( data [, data ...] )`__

Expand All @@ -425,7 +417,7 @@ the parameter data type.

This method returns `this` object. So you can chain to call a next method.

### To Add column(s)
#### To Add column(s)

If the type of `data` is a primitive type such as string or number,
these are added to the current row as individual columns.
Expand All @@ -445,7 +437,7 @@ The above code make same result as below:
EQUIVALENT CODE: buffer.d(1,2,3,4,5,6).nl();
```

### To add row(s)
#### To add row(s)

If the parameter `data` is an array contains one or more primitive data at least,
it will added as one closed row.
Expand All @@ -468,17 +460,15 @@ EQUIVALENT CODE: buffer.d([ [1,2,3], [4,5,6] ]);
```


ListIt#nl
-----------
### ListIt#nl

__`nl()`__

Ends up a process for the current row.

This method also returns `this` object.

ListIt#toString
-----------------
### ListIt#toString

__`toString()`__

Expand All @@ -488,4 +478,4 @@ Returns preformatted text table.
LICENSE
-------

MIT
This software is released under the MIT License, see [LICENSE](LICENSE)

0 comments on commit 0d9fcd0

Please sign in to comment.