Skip to content

Commit

Permalink
added option to NOT count up duplicate headings
Browse files Browse the repository at this point in the history
  • Loading branch information
maugenst committed Jun 4, 2018
1 parent 625927e commit 6e0b839
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/tabletojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class tabletojson {
stripHtmlFromHeadings: true,
stripHtmlFromCells: true,
stripHtml: null,
forceIndexAsNumber: false
forceIndexAsNumber: false,
countDuplicateHeadings: true
},
options
);
Expand Down Expand Up @@ -65,7 +66,7 @@ class tabletojson {
.trim();

var seen = alreadySeen[value];
if (seen) {
if (seen && options.countDuplicateHeadings) {
suffix = ++alreadySeen[value];
columnHeadings[j] = value + '_' + suffix;
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"name": "tabletojson",
"description": "Converts HTML tables to JSON objects",
"version": "0.9.1",
"version": "0.9.2",
"main": "./lib/tabletojson.js",
"keywords": [
"table2json",
Expand Down
12 changes: 12 additions & 0 deletions test/test-tabletojson-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ describe('TableToJSON Local', function() {
_.has(firstTable[0], 'isDumb_2').should.be.true();
});

it('Double Header Entry: do not count duplicate headings', async function() {
const converted = await tabletojson.convert(html, {
countDuplicateHeadings: false
});
converted.should.be.ok();

const firstTable = converted[0];

_.has(firstTable[0], 'isDumb').should.be.true();
_.has(firstTable[0], 'isDumb_2').should.be.false();
});

it('Directly local html content: Table with header', async function() {
const converted = await tabletojson.convert(html);
converted.should.be.ok();
Expand Down

0 comments on commit 6e0b839

Please sign in to comment.