@edadma/table 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -0
- package/index.d.ts +54 -0
- package/main.js +15314 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @edadma/table
|
|
2
|
+
|
|
3
|
+
Text table rendering with multiple border styles, column alignment, ANSI formatting, and Markdown output.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @edadma/table
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import { TextTable } from '@edadma/table';
|
|
15
|
+
|
|
16
|
+
const t = new TextTable({ border: 'light', columnDividers: true, headerLine: true, headerUnderlined: false });
|
|
17
|
+
t.header(['name', 'department', 'salary']);
|
|
18
|
+
t.row(['Alice', 'Engineering', 95000]);
|
|
19
|
+
t.row(['Bob', 'Sales', 72000]);
|
|
20
|
+
t.row(['Charlie', 'Marketing', 88000]);
|
|
21
|
+
t.rightAlignment(3);
|
|
22
|
+
console.log(t.render());
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Output:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
┌─────────┬─────────────┬────────┐
|
|
29
|
+
│ name │ department │ salary │
|
|
30
|
+
├─────────┼─────────────┼────────┤
|
|
31
|
+
│ Alice │ Engineering │ 95000 │
|
|
32
|
+
│ Bob │ Sales │ 72000 │
|
|
33
|
+
│ Charlie │ Marketing │ 88000 │
|
|
34
|
+
└─────────┴─────────────┴────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Border Styles
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
new TextTable() // no border (default)
|
|
41
|
+
new TextTable({ border: 'light' }) // ┌─┬─┐ │ │ └─┴─┘
|
|
42
|
+
new TextTable({ border: 'heavy' }) // ┏━┳━┓ ┃ ┃ ┗━┻━┛
|
|
43
|
+
new TextTable({ border: 'double' }) // Unicode double lines
|
|
44
|
+
new TextTable({ border: 'ascii' }) // +-+-+ | | +-+-+
|
|
45
|
+
new TextTable({ markdown: true }) // | col | col |
|
|
46
|
+
new TextTable({ tabbed: true }) // tab-separated
|
|
47
|
+
new TextTable({ matrix: true }) // ⎡ ⎤ ⎢ ⎥ ⎣ ⎦
|
|
48
|
+
new TextTable({ matrix: true, matrixRounded: true }) // ⎛ ⎞ ⎜ ⎟ ⎝ ⎠
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Options
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
|--------|------|---------|-------------|
|
|
55
|
+
| `border` | `'light' \| 'heavy' \| 'double' \| 'ascii'` | none | Border style |
|
|
56
|
+
| `columnDividers` | `boolean` | `false` | Show vertical separators between columns |
|
|
57
|
+
| `headerBold` | `boolean` | `true` | Bold header text (ANSI) |
|
|
58
|
+
| `headerLine` | `boolean` | `false` | Horizontal line after header |
|
|
59
|
+
| `headerUnderlined` | `boolean` | `true` | Underline header text (ANSI) |
|
|
60
|
+
| `headerCentered` | `boolean` | `true` | Center header text |
|
|
61
|
+
| `matrix` | `boolean` | `false` | Matrix bracket mode |
|
|
62
|
+
| `matrixRounded` | `boolean` | `false` | Use rounded parentheses for matrix |
|
|
63
|
+
| `markdown` | `boolean` | `false` | Markdown table output |
|
|
64
|
+
| `tabbed` | `boolean` | `false` | Tab-separated output |
|
|
65
|
+
| `noAnsi` | `boolean` | `false` | Disable ANSI escape codes |
|
|
66
|
+
|
|
67
|
+
## API
|
|
68
|
+
|
|
69
|
+
All methods return `this` for chaining.
|
|
70
|
+
|
|
71
|
+
### `header(columns: string[])`
|
|
72
|
+
|
|
73
|
+
Set the header row.
|
|
74
|
+
|
|
75
|
+
### `row(columns: any[])`
|
|
76
|
+
|
|
77
|
+
Add a data row. Values are converted to strings. `null` and `undefined` render as `"null"`.
|
|
78
|
+
|
|
79
|
+
### `rightAlignment(col: number)`
|
|
80
|
+
|
|
81
|
+
Right-align a column (1-based index).
|
|
82
|
+
|
|
83
|
+
### `columnAlignment(col: number, align: Alignment)`
|
|
84
|
+
|
|
85
|
+
Set the default alignment for a column. `align` is `'left'`, `'right'`, or `'center'`.
|
|
86
|
+
|
|
87
|
+
### `alignment(col: number, align: Alignment)`
|
|
88
|
+
|
|
89
|
+
Override alignment for a specific cell in the last added row.
|
|
90
|
+
|
|
91
|
+
### `style(col: number, ansiStyle: string)`
|
|
92
|
+
|
|
93
|
+
Apply an ANSI style code to a cell in the last added row. Example: `'\x1b[31m'` for red.
|
|
94
|
+
|
|
95
|
+
### `line()`
|
|
96
|
+
|
|
97
|
+
Insert a horizontal separator line at the current position.
|
|
98
|
+
|
|
99
|
+
### `render(): string`
|
|
100
|
+
|
|
101
|
+
Render the table to a string.
|
|
102
|
+
|
|
103
|
+
## Examples
|
|
104
|
+
|
|
105
|
+
### Markdown
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
const t = new TextTable({ markdown: true });
|
|
109
|
+
t.header(['Feature', 'Status']);
|
|
110
|
+
t.row(['Tables', 'Done']);
|
|
111
|
+
t.row(['Borders', 'Done']);
|
|
112
|
+
console.log(t.render());
|
|
113
|
+
// | Feature | Status |
|
|
114
|
+
// | ------- | ------ |
|
|
115
|
+
// | Tables | Done |
|
|
116
|
+
// | Borders | Done |
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Chaining
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
const output = new TextTable({ border: 'ascii', columnDividers: true, headerLine: true, headerUnderlined: false })
|
|
123
|
+
.header(['x', 'x^2'])
|
|
124
|
+
.row([1, 1])
|
|
125
|
+
.row([2, 4])
|
|
126
|
+
.row([3, 9])
|
|
127
|
+
.rightAlignment(1)
|
|
128
|
+
.rightAlignment(2)
|
|
129
|
+
.render();
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Line Separators
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const t = new TextTable();
|
|
136
|
+
t.header(['Group', 'Value']);
|
|
137
|
+
t.row(['A', 1]);
|
|
138
|
+
t.row(['A', 2]);
|
|
139
|
+
t.line();
|
|
140
|
+
t.row(['B', 3]);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
[ISC](https://opensource.org/licenses/ISC)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type Alignment = 'left' | 'right' | 'center';
|
|
2
|
+
|
|
3
|
+
export interface TextTableOptions {
|
|
4
|
+
/** Border style: 'light', 'heavy', 'double', 'ascii', or omit for no border */
|
|
5
|
+
border?: 'light' | 'heavy' | 'double' | 'ascii';
|
|
6
|
+
/** Show vertical column dividers */
|
|
7
|
+
columnDividers?: boolean;
|
|
8
|
+
/** Bold header text (ANSI) */
|
|
9
|
+
headerBold?: boolean;
|
|
10
|
+
/** Show horizontal line after header */
|
|
11
|
+
headerLine?: boolean;
|
|
12
|
+
/** Underline header text (ANSI) */
|
|
13
|
+
headerUnderlined?: boolean;
|
|
14
|
+
/** Center header text */
|
|
15
|
+
headerCentered?: boolean;
|
|
16
|
+
/** Matrix bracket mode */
|
|
17
|
+
matrix?: boolean;
|
|
18
|
+
/** Use rounded parentheses for matrix brackets */
|
|
19
|
+
matrixRounded?: boolean;
|
|
20
|
+
/** Render as Markdown table */
|
|
21
|
+
markdown?: boolean;
|
|
22
|
+
/** Tab-separated output */
|
|
23
|
+
tabbed?: boolean;
|
|
24
|
+
/** Disable ANSI escape codes */
|
|
25
|
+
noAnsi?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class TextTable {
|
|
29
|
+
constructor(options?: TextTableOptions);
|
|
30
|
+
|
|
31
|
+
/** Set the header row */
|
|
32
|
+
header(columns: string[]): this;
|
|
33
|
+
|
|
34
|
+
/** Add a data row */
|
|
35
|
+
row(columns: any[]): this;
|
|
36
|
+
|
|
37
|
+
/** Right-align a column (1-based index) */
|
|
38
|
+
rightAlignment(col: number): this;
|
|
39
|
+
|
|
40
|
+
/** Set default alignment for a column (1-based index) */
|
|
41
|
+
columnAlignment(col: number, align: Alignment): this;
|
|
42
|
+
|
|
43
|
+
/** Set alignment for a cell in the last added row (1-based column index) */
|
|
44
|
+
alignment(col: number, align: Alignment): this;
|
|
45
|
+
|
|
46
|
+
/** Apply ANSI style to a cell in the last added row (1-based column index) */
|
|
47
|
+
style(col: number, ansiStyle: string): this;
|
|
48
|
+
|
|
49
|
+
/** Insert a horizontal separator line */
|
|
50
|
+
line(): this;
|
|
51
|
+
|
|
52
|
+
/** Render the table to a string */
|
|
53
|
+
render(): string;
|
|
54
|
+
}
|