Skip to content

Commit 8038d52

Browse files
committed
changes added in readme for oop
1 parent 9df9ed2 commit 8038d52

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ The following snippet shows importing the prettytable module, adding column head
99
The `create()` method takes list of headers and array of rows as inputs and creates the table in one shot.
1010

1111
```javascript
12-
pt = require('prettytable');
12+
PrettyTable = require('prettytable');
13+
pt = new PrettyTable();
1314

1415
var headers = ["name", "age", "city"];
1516

@@ -40,7 +41,8 @@ This gives you the following table on console.
4041
Alternatively, it is possible to add table headers separately and then add rows one by one.
4142

4243
```javascript
43-
pt = require('prettytable');
44+
PrettyTable = require('prettytable');
45+
pt = new PrettyTable();
4446

4547
pt.fieldNames(["City name", "Area", "Population", "ann"]);
4648

@@ -62,17 +64,23 @@ We are using `fieldNames()` method and passing a list of table headers. Method `
6264
Prettytable can load a local CSV file and print it on the console. It considers the first row to generate table headers.
6365

6466
```javascript
65-
pt = require('prettytable');
67+
PrettyTable = require('prettytable');
68+
pt = new PrettyTable();
69+
6670
pt.csv("myfile.csv");
71+
pt.print();
6772
```
6873

6974
### Importing from JSON File
7075

7176
Like CSV, Prettytable can load a local JSON file, parse through it and finally print it on the console. Table headers are automatically determined from the keys.
7277

7378
```javascript
74-
pt = require('prettytable');
79+
PrettyTable = require('prettytable');
80+
pt = new PrettyTable();
81+
7582
pt.json("myfile.json");
83+
pt.print();
7684
```
7785

7886
### Output Formats
@@ -82,7 +90,8 @@ Prettytable can print a table directly to the console, return as a string or pri
8290
The following example shows returning the table as plain text and then printing to the console.
8391

8492
```javascript
85-
pt = require('prettytable');
93+
PrettyTable = require('prettytable');
94+
pt = new PrettyTable();
8695

8796
pt.fieldNames(["City name", "Area", "Population", "ann"]);
8897

@@ -101,7 +110,8 @@ console.log(tableContent);
101110
The following example shows generating HTML table. User can also pass different attributes which will be added as inline HTML style.
102111

103112
```javascript
104-
pt = require('prettytable');
113+
PrettyTable = require('prettytable');
114+
pt = new PrettyTable();
105115

106116
pt.fieldNames(["City name", "Area", "Population", "ann"]);
107117

@@ -125,7 +135,8 @@ console.log(styledHTML);
125135
Prettytable also offers option to sort the table given a column name. Additional parameters can be passed to sort in ascending or descending order. If no parameter is passed, the table will be sorted in ascending order.
126136

127137
```javascript
128-
pt = require('prettytable');
138+
PrettyTable = require('prettytable');
139+
pt = new PrettyTable();
129140

130141
pt.fieldNames(["name", "age", "city"]);
131142

@@ -148,7 +159,8 @@ A single row can be deleted from the table by passing the row number to `deleteR
148159
The following example shows all 3 of these methods.
149160

150161
```javascript
151-
pt = require('prettytable');
162+
PrettyTable = require('prettytable');
163+
pt = new PrettyTable();
152164

153165
pt.fieldNames(["name", "age", "city"]);
154166

prettytable.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ PrettyTable.prototype.json = function(filename) {
175175
}
176176
this.addRow(rowVals);
177177
}
178-
return this.toString();
179178
};
180179

181180
// Sort the table given a column in ascending or descending order

0 commit comments

Comments
 (0)