Skip to content

Commit

Permalink
fix: Updating docs to include better examples (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayonious authored Dec 21, 2023
1 parent 865a0f5 commit 15ce90a
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 306 deletions.
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ const { printTable } = require('console-table-printer');

//Create a table
const testCases = [
{ index: 3, text: 'I would like some gelb bananen bitte', value: 100 },
{ index: 4, text: 'I hope batch update is working', value: 300 },
{ Rank: 3, text: 'I would like some Yellow', value: 100 },
{ Rank: 4, text: 'I hope batch update is working', value: 300 },
];

//print
printTable(testCases);
```

![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/quick-print.png)
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-quick-1.png)

## 🚨🚨Announcement🚨🚨 Official Documentation is moved [Here](https://console-table.netlify.app/docs)

Expand All @@ -57,39 +57,39 @@ const { Table } = require('console-table-printer');
//Create a table
const p = new Table();

//add rows with color
p.addRow({ index: 1, text: 'red wine please', value: 10.212 });
p.addRow({ index: 2, text: 'green gemuse please', value: 20.0 });
// add rows with color
p.addRow({ Record: 'a', text: 'red wine please', value: 10.212 });
p.addRow({ Record: 'b', text: 'green gemuse please', value: 20.0 });
p.addRows([
//adding multiple rows are possible
{ index: 3, text: 'gelb bananen bitte', value: 100 },
{ index: 4, text: 'update is working', value: 300 },
// adding multiple rows are possible
{ Record: 'c', text: 'gelb bananen bitte', value: 100 },
{ Record: 'd', text: 'update is working', value: 300 },
]);

//print
p.printTable();
```

![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-simple.png)
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-instance-1.png)

You can also put some color to your table like this:

```javascript
const p = new Table();
p.addRow({ index: 1, text: 'red wine', value: 10.212 }, { color: 'red' });
p.addRow({ index: 2, text: 'green gemuse', value: 20.0 }, { color: 'green' });
p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, { color: 'yellow' });
p.addRow({ description: 'red wine', value: 10.212 }, { color: 'red' });
p.addRow({ description: 'green gemuse', value: 20.0 }, { color: 'green' });
p.addRow({ description: 'gelb bananen', value: 100 }, { color: 'yellow' });
p.printTable();
```

![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-colored.png)
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-color-1.png)

You can also put properties based on columns (color/alignment/title)

```javascript
const p = new Table({
columns: [
{ name: 'index', alignment: 'left', color: 'blue' }, // with alignment and color
{ name: 'id', alignment: 'left', color: 'blue' }, // with alignment and color
{ name: 'text', alignment: 'right' },
{ name: 'is_priority_today', title: 'Is This Priority?' }, // with Title as separate Text
],
Expand All @@ -98,23 +98,21 @@ const p = new Table({
},
});

p.addRow({ index: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
p.addRow({ id: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
p.addRow(
{ index: 2, text: 'green gemuse', value: 20.0 },
{ id: 2, text: 'green gemuse', value: 20.0 },
{ color: 'custom_green' } // your green
);
p.addRow(
{ index: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
{ id: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
{ color: 'yellow' }
);
p.addRow(
{ index: 3, text: 'rosa hemd wie immer', value: 100 },
{ color: 'cyan' }
);
p.addRow({ id: 3, text: 'rosa hemd wie immer', value: 100 }, { color: 'cyan' });

p.printTable();
```

![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-column-props-2.png)
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-columns-1.png)

## CLI

Expand Down
Binary file removed static-resources/quick-print.png
Binary file not shown.
Binary file added static-resources/readme-color-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static-resources/readme-columns-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static-resources/readme-instance-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static-resources/readme-quick-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed static-resources/screenshot-colored.png
Binary file not shown.
Binary file removed static-resources/screenshot-column-props-2.png
Binary file not shown.
Binary file removed static-resources/screenshot-fat-border.png
Binary file not shown.
Binary file removed static-resources/screenshot-simple.png
Binary file not shown.
Binary file removed static-resources/screenshot-thin-border.png
Binary file not shown.
136 changes: 0 additions & 136 deletions test/readme/readmeExamples1.test.ts

This file was deleted.

15 changes: 15 additions & 0 deletions test/readme/readmeExamples1Basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { printTable } from '../../index';

describe('Example: 1', () => {
it('Basic', () => {
// Create a table
const testCases = [
{ Rank: 3, text: 'I would like some Yellow', value: 100 },
{ Rank: 4, text: 'I hope batch update is working', value: 300 },
];

// print
const returned = printTable(testCases);
expect(returned).toBeUndefined();
});
});
77 changes: 0 additions & 77 deletions test/readme/readmeExamples2.test.ts

This file was deleted.

22 changes: 22 additions & 0 deletions test/readme/readmeExamples2Instance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Table } from '../../index';

describe('Example: 2', () => {
it('Instance', () => {
// Create a table
const p = new Table();

// add rows with color
p.addRow({ Record: 'a', text: 'red wine please', value: 10.212 });
p.addRow({ Record: 'b', text: 'green gemuse please', value: 20.0 });
p.addRows([
// adding multiple rows are possible
{ Record: 'c', text: 'gelb bananen bitte', value: 100 },
{ Record: 'd', text: 'update is working', value: 300 },
]);

// print
const returned = p.printTable();

expect(returned).toBeUndefined();
});
});
33 changes: 0 additions & 33 deletions test/readme/readmeExamples3.test.ts

This file was deleted.

Loading

0 comments on commit 15ce90a

Please sign in to comment.