@@ -9,6 +9,7 @@ interface Options {
99 hSelector ?: string
1010 bSelector ?: [ string , string ]
1111 format ?: Format
12+ headers ?: string [ ]
1213}
1314
1415/**
@@ -32,6 +33,7 @@ function jsonFromTable<T extends Format>(options: Options = {}) {
3233 hSelector = 'tr:first-child th' ,
3334 bSelector = [ 'tr:not(:first-child)' , 'td' ] ,
3435 format = 'object' ,
36+ headers : customHeaders = [ ] ,
3537 } = options
3638 // prettier-ignore
3739 const hSelectors = [ hSelector , "thead tr:first-child th" , "tr:first-child th" , "tr:first-child td" ] ;
@@ -57,14 +59,12 @@ function jsonFromTable<T extends Format>(options: Options = {}) {
5759 if ( table . html ( ) === null )
5860 throw new Error ( `Couldn't find table with selector "${ selector } "` )
5961
60- const headers = getHeaders ( $ , table , hSelectors )
61- const body = getBody ( $ , table , bSelectors )
62+ const headers =
63+ customHeaders . length > 0
64+ ? customHeaders
65+ : getHeaders ( $ , table , hSelectors )
6266
63- if ( headers . values . length !== body . values . length ) {
64- console . warn (
65- `Length of body and head is not same:\nHeader: ${ headers . values . length } \nBody: ${ body . values . length } `
66- )
67- }
67+ const body = getBody ( $ , table , bSelectors )
6868
6969 return output ( headers , body , format ) as Result < T >
7070 }
0 commit comments