Skip to content

Commit 73de9ad

Browse files
committed
fix(table): rows are now correctly string[][]
1 parent f85c3ac commit 73de9ad

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export class Markdown {
6565
return this;
6666
}
6767

68-
table(columns = [], rows = [], fmtFnc?): this {
69-
this.addLine(table(columns, rows, fmtFnc));
68+
table(columns = [], rows = []): this {
69+
this.addLine(table(columns, rows));
7070
return this;
7171
}
7272

src/utils/common.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export const CR = '\n\n';
22
export const LB = '\n';
33

4-
export const table = (
5-
headers: string[] = [],
6-
rows: string[] = [],
7-
fmtFnc = (rowValue: any) => rowValue
8-
) => {
4+
export const table = (headers: string[] = [], rows: string[][] = []) => {
95
let t = '';
106
t += `| ${headers.join(' | ')} |${LB}|${' --- |'.repeat(headers.length)}`;
11-
t += `${LB}| ${rows.map(fmtFnc).join(' | ')} |`;
7+
8+
for (const row of rows) {
9+
t += `${LB}| ${row.join(' | ')} |`;
10+
}
11+
1212
return t;
1313
};
1414

test/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ tap.test('code', (t) => {
5050

5151
tap.test('table', (t) => {
5252
const headers = ['id', 'name'];
53-
const rows = ['1', 'Ajeje'];
53+
const rows = [['1', 'Ajeje']];
5454
let out = '| id | name |\n';
5555
out += '| --- | --- |\n';
5656
out += '| 1 | Ajeje |';

test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tap.test('Shoud generate Markdown', async (t) => {
3030
)}`
3131
)
3232
.header('Table', 2)
33-
.table(['id', 'name'], ['1', 'Simone'])
33+
.table(['id', 'name'], [['1', 'Simone']])
3434
.header('List', 2)
3535
.list([
3636
{ text: 'list1', depth: 0 },

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export declare class Markdown {
1717
paragraph(data: string | number): this;
1818
header(title: string, n?: number): this;
1919
image(filepath: string, altText?: string): this;
20-
table(columns?: any[], rows?: any[], fmtFnc?: any): this;
20+
table(columns?: any[], rows?: any[]): this;
2121
list(items?: ListItems<ListItem>, numbered?: boolean): this;
2222
tasks(items?: ListItems<TaskItem>): this;
2323
}

types/utils/common.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export declare const CR = "\n\n";
22
export declare const LB = "\n";
3-
export declare const table: (headers?: string[], rows?: string[], fmtFnc?: (rowValue: any) => any) => string;
3+
export declare const table: (headers?: string[], rows?: string[][]) => string;
44
export declare const italic: (text?: string) => string;
55
export declare const bold: (text?: string) => string;
66
export declare const link: (text: any, url: any) => string;

0 commit comments

Comments
 (0)