Gathering detailed insights and metrics for tabletojson
Gathering detailed insights and metrics for tabletojson
Gathering detailed insights and metrics for tabletojson
Gathering detailed insights and metrics for tabletojson
npm install tabletojson
Typescript
Module System
Min. Node Version
Node Version
NPM Version
56.2
Supply Chain
97.8
Quality
85.6
Maintenance
100
Vulnerability
99.6
License
TypeScript (61.38%)
HTML (38.37%)
Shell (0.25%)
Total Downloads
1,771,151
Last Day
753
Last Week
11,191
Last Month
46,074
Last Year
567,949
142 Stars
184 Commits
38 Forks
10 Watching
7 Branches
14 Contributors
Latest Version
4.1.5
Package Id
tabletojson@4.1.5
Unpacked Size
222.87 kB
Size
51.03 kB
File Count
19
NPM Version
10.9.0
Node Version
22.11.0
Publised On
06 Nov 2024
Cumulative downloads
Total Downloads
Last day
-4%
753
Compared to previous day
Last week
7.9%
11,191
Compared to previous week
Last month
-12.1%
46,074
Compared to previous month
Last year
61.6%
567,949
Compared to previous year
Convert local or remote HTML embedded tables into JSON objects.
Tabletojson attempts to convert local or remote HTML tables into JSON with a very low footprint. Can be passed the markup for a single table as a string, a fragment of HTML or an entire page or just a URL (with an optional callback function; promises also supported).
The response is always an array. Every array entry in the response represents a table found on the page (in same the order they were found in HTML).
As of version 2.0 tabletojson is completely written in typescript.
const tabletojson = require('../lib/tabletojson');
to either
const tabletojson = require('../lib/tabletojson').Tabletojson;
or
const {Tabletojson: tabletojson} = require('../lib/tabletojson');
import {Tabletojson as tabletojson} from 'tabletojson';
or import {tabletojson} from 'tabletojson';
import {tabletojson} from 'tabletojson';
1npm run build:examples 2cd dist/examples 3node --experimental-vm-modules --experimental-specifier-resolution=node example-1.js --prefix=dist/examples
1npm install tabletojson
1import {tabletojson} from 'tabletojson'; 2tabletojson.convertUrl('https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes', function (tablesAsJson) { 3 console.log(tablesAsJson[1]); 4});
1const {tabletojson} = require('tabletojson'); 2tabletojson.convertUrl('https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes', function (tablesAsJson) { 3 console.log(tablesAsJson[1]); 4});
convertUrl
)1// example-1.ts 2import {tabletojson} from 'tabletojson'; 3tabletojson.convertUrl('https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes', function (tablesAsJson) { 4 console.log(tablesAsJson[1]); 5});
convert
)More examples can be found in examples folder.
1// example-6.ts 2import {tabletojson} from 'tabletojson'; 3import * as fs from 'fs'; 4import * as path from 'path'; 5const html = fs.readFileSync(path.resolve(process.cwd(), '../../test/tables.html'), { 6 encoding: 'utf-8', 7}); 8const converted = tabletojson.convert(html); 9console.log(converted);
Tables with duplicate column headings, subsequent headings are suffixed with a count:
1|| PLACE || VALUE || PLACE || VALUE || 2|--------|--------|--------|---------| 3| abc | 1 | def | 2 |
1[ 2 { 3 "PLACE": "abc", 4 "VALUE": "1", 5 "PLACE_2": "def", 6 "VALUE_2": "2" 7 } 8]
In tables with rowspan, the content of the spawned cell must be available in the respective object.
Parent | Child | Age |
---|---|---|
Marry | Sue | 15 |
Steve | 12 | |
Tom | 3 |
1[ 2 {"Parent": "Marry", "Child": "Tom", "Age": "3"}, 3 {"Parent": "Marry", "Child": "Steve", "Age": "12"}, 4 {"Parent": "Marry", "Child": "Sue", "Age": "15"} 5]
In tables with complex rowspans, the content of the spawned cell must be available in the respective object.
Parent | Child | Age |
---|---|---|
Marry | Sue | 15 |
Steve | 12 | |
Tom | 3 | |
Taylor | ||
Peter | 17 |
1[ 2 {"Parent": "Marry", "Child": "Sue", "Age": "15"}, 3 {"Parent": "Marry", "Child": "Steve", "Age": "12"}, 4 {"Parent": "Marry", "Child": "Tom", "Age": "3"}, 5 {"Parent": "Taylor", "Child": "Tom", "Age": "3"}, 6 {"Parent": "Taylor", "Child": "Peter", "Age": "17"} 7]
In tables with even more complex rowspans, the content of the spawned cell must be available in the respective object.
Department | Major | Class | Instructor | Credit |
---|---|---|---|---|
Engineering | Computer Science | CS101 | Kim | 3 |
CS201 | Garcia | |||
CS303 | 2 | |||
Electrical Engineering | EE101 | Müller | 3 | |
Social Science | Economics | EC101 | Nguyen | 3 |
EC401 | Smith |
1[ 2 { 3 "Department": "Engineering", 4 "Major": "Computer Science", 5 "Class": "CS101", 6 "Instructor": "Kim", 7 "Credit": "3" 8 }, 9 { 10 "Department": "Engineering", 11 "Major": "Computer Science", 12 "Credit": "3", 13 "Class": "CS201", 14 "Instructor": "Garcia" 15 }, 16 { 17 "Department": "Engineering", 18 "Major": "Computer Science", 19 "Instructor": "Garcia", 20 "Class": "CS303", 21 "Credit": "2" 22 }, 23 { 24 "Department": "Engineering", 25 "Major": "Electrical Engineering", 26 "Class": "EE101", 27 "Instructor": "Müller", 28 "Credit": "3" 29 }, 30 { 31 "Department": "Social Science", 32 "Major": "Economics", 33 "Class": "EC101", 34 "Instructor": "Nguyen", 35 "Credit": "3" 36 }, 37 { 38 "Department": "Social Science", 39 "Major": "Economics", 40 "Credit": "3", 41 "Class": "EC401", 42 "Instructor": "Smith" 43 } 44]
If a table contains headings in the first column you might get an unexpected
result, but you can pass a second argument with options with
{ useFirstRowForHeadings: true }
to have it treat the first column as it would
any other cell.
1tabletojson.convertUrl( 2 'https://www.timeanddate.com/holidays/ireland/2017', 3 { useFirstRowForHeadings: true }, 4 function(tablesAsJson) { 5 console.log(tablesAsJson); 6 } 7);
The following options are true by default, which converts all values to plain text to give you an easier more readable object to work with:
If your table contains HTML you want to parse (for example for links) you can
set stripHtmlFromCells
to false
to treat it as raw text.
1tabletojson.convertUrl( 2 'https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes', 3 { stripHtmlFromCells: false }, 4 function(tablesAsJson) { 5 //Print out the 1st row from the 2nd table on the above webpage as JSON 6 console.log(tablesAsJson[1][0]); 7 } 8);
Note: This doesn't work with nested tables, which it will still try to parse.
You probably don't need to set stripHtmlFromHeadings
to false
(and setting
it to false can make the results hard to parse), but if you do you can also set
both at the same time by setting stripHtml
to false
.
Use the following rows as keys in the output json object. The values are flattened and concatenated the values with 'concatWith' [default=undefined]
Input:
Industry | Operating income | Operating costs | Total profit | ||||||
amount (billion) | Year-over-year growth (%) | amount (billion) | Year-over-year growth (%) | amount (billion) | Year-over-year growth (%) | ||||
$ | €* | $ | €* | $ | €* | ||||
total | 843280,70 | 758952,63 | -0,30 | 718255,00 | 646429,50 | 0,20 | 46558,20 | 41902,38 | -11,70 |
Coal mining and washing industry | 22937,30 | 20643,57 | -13,90 | 14653,70 | 13188,33 | -7,50 | 5236,90 | 4713,21 | -26,30 |
Oil and gas extraction | 7605,10 | 6844,59 | -9,60 | 3863,60 | 3477,24 | 0,10 | 2592,70 | 2333,43 | -10,80 |
Ferrous metal mining and dressing industry | 3010,70 | 2709,63 | -4,40 | 2369,10 | 2132,19 | -4,10 | 326,60 | 293,94 | -23,80 |
Non-ferrous metal mining and dressing industry | 2180,90 | 1962,81 | -0,30 | 1394,30 | 1254,87 | -2,50 | 512,10 | 460,89 | 4,00 |
Non-metallic ore mining and dressing industry | 2244,70 | 2020,23 | -5,70 | 1612,00 | 1450,80 | -5,70 | 236,10 | 212,49 | -7,00 |
Mining professional and ancillary activities | 1537,30 | 1383,57 | 12,70 | 1453,70 | 1308,33 | 11,80 | 2,60 | 2,34 | -77,00 |
Note: Some indicators in this table have a situation where the total is not equal to the sum of the sub-items, which is due to rounding of the data and has not been mechanically adjusted. * Conversion rate: 1$=0,9€ |
Output:
1[ 2 { 3 "Industry": "total", 4 "Operating income amount (billion) $": "843280,70", 5 "Operating income amount (billion) €*": "758952,63", 6 "Operating income Year-over-year growth (%)": "-0,30", 7 "Operating costs amount (billion) $": "718255,00", 8 "Operating costs amount (billion) €*": "646429,50", 9 "Operating costs Year-over-year growth (%)": "0,20", 10 "Total profit amount (billion) $": "46558,20", 11 "Total profit amount (billion) €*": "41902,38", 12 "Total profit Year-over-year growth (%)": "-11,70" 13 }, 14 { 15 "Industry": "Coal mining and washing industry", 16 "Operating income amount (billion) $": "22937,30", 17 "Operating income amount (billion) €*": "20643,57", 18 "Operating income Year-over-year growth (%)": "-13,90", 19 "Operating costs amount (billion) $": "14653,70", 20 "Operating costs amount (billion) €*": "13188,33", 21 "Operating costs Year-over-year growth (%)": "-7,50", 22 "Total profit amount (billion) $": "5236,90", 23 "Total profit amount (billion) €*": "4713,21", 24 "Total profit Year-over-year growth (%)": "-26,30" 25 }, 26 { 27 "Industry": "Oil and gas extraction", 28 "Operating income amount (billion) $": "7605,10", 29 "Operating income amount (billion) €*": "6844,59", 30 "Operating income Year-over-year growth (%)": "-9,60", 31 "Operating costs amount (billion) $": "3863,60", 32 "Operating costs amount (billion) €*": "3477,24", 33 "Operating costs Year-over-year growth (%)": "0,10", 34 "Total profit amount (billion) $": "2592,70", 35 "Total profit amount (billion) €*": "2333,43", 36 "Total profit Year-over-year growth (%)": "-10,80" 37 }, 38 { 39 "Industry": "Ferrous metal mining and dressing industry", 40 "Operating income amount (billion) $": "3010,70", 41 "Operating income amount (billion) €*": "2709,63", 42 "Operating income Year-over-year growth (%)": "-4,40", 43 "Operating costs amount (billion) $": "2369,10", 44 "Operating costs amount (billion) €*": "2132,19", 45 "Operating costs Year-over-year growth (%)": "-4,10", 46 "Total profit amount (billion) $": "326,60", 47 "Total profit amount (billion) €*": "293,94", 48 "Total profit Year-over-year growth (%)": "-23,80" 49 }, 50 { 51 "Industry": "Non-ferrous metal mining and dressing industry", 52 "Operating income amount (billion) $": "2180,90", 53 "Operating income amount (billion) €*": "1962,81", 54 "Operating income Year-over-year growth (%)": "-0,30", 55 "Operating costs amount (billion) $": "1394,30", 56 "Operating costs amount (billion) €*": "1254,87", 57 "Operating costs Year-over-year growth (%)": "-2,50", 58 "Total profit amount (billion) $": "512,10", 59 "Total profit amount (billion) €*": "460,89", 60 "Total profit Year-over-year growth (%)": "4,00" 61 }, 62 { 63 "Industry": "Non-metallic ore mining and dressing industry", 64 "Operating income amount (billion) $": "2244,70", 65 "Operating income amount (billion) €*": "2020,23", 66 "Operating income Year-over-year growth (%)": "-5,70", 67 "Operating costs amount (billion) $": "1612,00", 68 "Operating costs amount (billion) €*": "1450,80", 69 "Operating costs Year-over-year growth (%)": "-5,70", 70 "Total profit amount (billion) $": "236,10", 71 "Total profit amount (billion) €*": "212,49", 72 "Total profit Year-over-year growth (%)": "-7,00" 73 }, 74 { 75 "Industry": "Mining professional and ancillary activities", 76 "Operating income amount (billion) $": "1537,30", 77 "Operating income amount (billion) €*": "1383,57", 78 "Operating income Year-over-year growth (%)": "12,70", 79 "Operating costs amount (billion) $": "1453,70", 80 "Operating costs amount (billion) €*": "1308,33", 81 "Operating costs Year-over-year growth (%)": "11,80", 82 "Total profit amount (billion) $": "2,60", 83 "Total profit amount (billion) €*": "2,34", 84 "Total profit Year-over-year growth (%)": "-77,00" 85 }, 86 { 87 "Industry": "Note: Some indicators in this table have a situation where the total is not equal to the sum of the sub-items, which is due to rounding of the data and has not been mechanically adjusted.\n * Conversion rate: 1$=0,9€" 88 } 89]
convertUrl
)Tabletojson is using fetch api which is available in node from version 17.5.0 onwards to fetch remote HTML pages. See
mdn web docs on fetch for more information. The usage of
Tabletojson should now be the same in node as in browsers.
So if you need to get data from a remote server you can call tabletojson.convertUrl
and pass any
fetch-options (proxy, headers,...) by adding a RequestInit object to the options
passed to convertUrl
. For more information on how to configure request please
have a look at Browser Syntax or Node fetch
1tabletojson.convertUrl('https://www.timeanddate.com/holidays/ireland/2017', { 2 useFirstRowForHeadings: true, 3 fetchOptions: { 4 ... 5 } 6});
Define the rows to be used as keys in the output json object. The values will be concatenated with the given concatWith value. [default=undefined]
1const html = fs.readFileSync(path.resolve(process.cwd(), '../test/tables.html'), { 2 encoding: 'utf-8', 3}); 4const converted = tabletojson.convert(html, { 5 id: ['table15'], 6 7 // from (Optional) Start row [default=0] 8 // to End row 9 // concatWith Concatenate the values with this string 10 11 headers: { 12 to: 2, 13 concatWith: ' ', 14 }, 15}); 16console.log(JSON.stringify(converted, null, 2));
Strip any HTML from heading cells. Default is true.
1||KEY || <b>VALUE</b><|| 2|-----|----------------| 3| abc | 1 | 4| dev | 2 |
Example output with stripHtmlFromHeadings:true
1[ 2 { 3 "KEY": "abc", "VALUE": "1" 4 }, 5 { 6 "KEY": "dev", "VALUE": "2" 7 } 8]
Example output with stripHtmlFromHeadings:false
1[ 2 { 3 "KEY": "abc", "<b>VALUE</b>": "1" 4 }, 5 { 6 "KEY": "dev", "<b>VALUE</b>": "2" 7 } 8]
Strip any HTML from tableBody cells. Default is true.
1||KEY || VALUE|| 2|-----|-----------| 3|abc | <i>1</i>| 4|dev | <i>2</i>|
Example output with stripHtmlFromHeadings:true
1[ 2 { 3 "KEY": "abc", "VALUE": "1" 4 }, 5 { 6 "KEY": "dev", "VALUE": "2" 7 } 8]
Example output with stripHtmlFromHeadings:false
1[ 2 { 3 "KEY": "abc", "VALUE": "<i>1</i>" 4 }, 5 { 6 "KEY": "dev", "VALUE": "<i>2</i>" 7 } 8]
Instead of using column text (that sometime re-order the data), force an index as a number (string number).
1{ 2 "0": "", 3 "1": "A会", 4 "2": "B会", 5 "3": "C会", 6 "4": "Something", 7 "5": "Else", 8 "6": "" 9}
Default is true
. If set to false
, duplicate headings will not get a trailing
number. The value of the field will be the last value found in the table row:
1||PLACE || VALUE || PLACE || VALUE|| 2|-------|--------|--------|--------| 3| abc | 1 | def | 2 | 4| ghi | 3 | jkl | 4 |
Example output with countDuplicateHeadings:false
1[ 2 { 3 "PLACE": "def", "VALUE": "2" 4 }, 5 { 6 "PLACE": "jkl", "VALUE": "4" 7 } 8]
Array of indexes to be ignored, starting with 0. Default is 'null/undefined'.
1|| NAME || PLACE || WEIGHT || SEX || AGE || 2|-------|--------|---------|------|-------| 3| Mel | 1 | 58 | W | 23 | 4| Bill | 3 | 92 | M | 31 | 5| Tom | 2 | 78 | M | 54 |
Example output with ignoreColumns: [2, 3]
1[ 2 { 3 "NAME": "Mel", "PLACE": "1", "AGE": "23" 4 }, 5 { 6 "NAME": "Tom", "PLACE": "2", "AGE": "54" 7 }, 8 { 9 "NAME": "Bill", "PLACE": "3", "AGE": "31" 10 } 11]
Array of indexes that are taken, starting with 0. Default is 'null/undefined'. If given, this option overrides ignoreColumns.
1|| NAME || PLACE || WEIGHT || SEX || AGE || 2|-------|--------|---------|------|-------| 3| Mel | 1 | 58 | W | 23| 4| Tom | 2 | 78 | M | 54| 5| Bill | 3 | 92 | M | 31|
Example output with onlyColumns: [0, 4]
1[ 2 { 3 "NAME": "Mel", "AGE": "23" 4 }, 5 { 6 "NAME": "Tom", "AGE": "54" 7 }, 8 { 9 "NAME": "Bill", "AGE": "31" 10 } 11]
Indicates if hidden rows (display:none) are ignored. Default is true:
1|| NAME || PLACE || WEIGHT || SEX || AGE || 2|-------|--------|---------|------|-------| 3| Mel | 1 | 58 | W | 23| 4| Tom | 2 | 78 | M | 54| 5| Bill | 3 | 92 | M | 31| 6|* Cat | 4 | 4 | W | 2*|
Example output with ignoreHiddenRows:true
1[ 2 { 3 "NAME":"Mel", 4 "PLACE":"1", 5 "WEIGHT":"58", 6 "SEX":"W", 7 "AGE":"23" 8 }, 9 { 10 "NAME":"Tom", 11 "PLACE":"2", 12 "WEIGHT":"78", 13 "SEX":"M", 14 "AGE":"54" 15 }, 16 { 17 "NAME":"Bill", 18 "PLACE":"3", 19 "WEIGHT":"92", 20 "SEX":"M", 21 "AGE":"31" 22 } 23]
Example output with ignoreHiddenRows:false
1[ 2 { 3 "NAME":"Mel", 4 "PLACE":"1", 5 "WEIGHT":"58", 6 "SEX":"W", 7 "AGE":"23" 8 }, 9 { 10 "NAME":"Tom", 11 "PLACE":"2", 12 "WEIGHT":"78", 13 "SEX":"M", 14 "AGE":"54" 15 }, 16 { 17 "NAME":"Bill", 18 "PLACE":"3", 19 "WEIGHT":"92", 20 "SEX":"M", 21 "AGE":"31" 22 }, 23 { 24 "NAME":"Cat", 25 "PLACE":"4", 26 "WEIGHT":"4", 27 "SEX":"W", 28 "AGE":"2" 29 } 30]
Array of Strings to be used as headings. Default is null
/undefined
.
If more headings are given than columns exist the overcounting ones will be ignored. If less headings are given than existing values the overcounting values are ignored.
1|| NAME || PLACE || WEIGHT || SEX || AGE || 2|-------|--------|---------|------|-------| 3| Mel | 1 | 58 | W | 23| 4| Tom | 2 | 78 | M | 54| 5| Bill | 3 | 92 | M | 31| 6|* Cat | 4 | 4 | W | 2*|
Example output with headings: ['A','B','C','D','E']
1[ 2 { 3 "A":"Mel", 4 "B":"1", 5 "C":"58", 6 "D":"W", 7 "E":"23" 8 }, 9 { 10 "A":"Tom", 11 "B":"2", 12 "C":"78", 13 "D":"M", 14 "E":"54" 15 }, 16 { 17 "A":"Bill", 18 "B":"3", 19 "C":"92", 20 "D":"M", 21 "E":"31" 22 } 23]
Example output with headings: ['A','B','C']
1[ 2 { 3 "A":"Mel", 4 "B":"1", 5 "C":"58" 6 }, 7 { 8 "A":"Tom", 9 "B":"2", 10 "C":"78" 11 }, 12 { 13 "A":"Bill", 14 "B":"3", 15 "C":"92" 16 } 17]
Example output with headings: ['A','B','C','D','E','F','G','H']
1[ 2 { 3 "A":"Mel", 4 "B":"1", 5 "C":"58", 6 "D":"W", 7 "E":"23" 8 }, 9 { 10 "A":"Tom", 11 "B":"2", 12 "C":"78", 13 "D":"M", 14 "E":"54" 15 }, 16 { 17 "A":"Bill", 18 "B":"3", 19 "C":"92", 20 "D":"M", 21 "E":"31" 22 } 23]
Example output with headings: ['A','B','C'] && ignoreColumns: [2, 3]
1[ 2 { 3 "A":"Mel", 4 "B":"W", 5 "C":"23" 6 }, 7 { 8 "A":"Tom", 9 "B":"M", 10 "C":"54" 11 }, 12 { 13 "A":"Bill", 14 "B":"M", 15 "C":"31" 16 } 17]
Number of rows to which the resulting object should be limited to. Default is
null
/undefined
.
1|| Roleplayer Number || Name || Text to say|| 2|--------------------|------------------|--------------| 3| 0 | Raife Parkinson | re dolor in hendrerit in vulputate ve| 4| 1 | Hazel Schultz | usto duo dolores et ea rebum. Ste| 5| 2 | Montana Delgado | psum dolor sit amet. Lorem ipsum dolor| 6| 3 | Dianne Mcbride | sit ame olor sit amet. Lorem ipsum| 7| 4 | Xena Lynch | us est Lorem ipsum dol| 8| 5 | Najma Holding | akimata sanctus est Lorem ipsum dolor sit| 9| 6 | Kiki House | ame nvidunt ut| 10|...| 11|197 | Montana Delgado | lores et ea rebum. Stet clita kasd gu a| 12|198 | Myrtle Conley | rebum. Stet clita kasd gubergren, no sea| 13|199 | Hanna Ellis | kimata sanctus est Lorem ipsum dolor si|
1[ 2 { 3 "Roleplayer Number":"0", 4 "Name":"Raife Parkinson", 5 "Text to say":"re dolor in hendrerit in vulputate ve" 6 }, 7 { 8 "Roleplayer Number":"1", 9 "Name":"Hazel Schultz", 10 "Text to say":"usto duo dolores et ea rebum. Ste" 11 }, 12 { 13 "Roleplayer Number":"2", 14 "Name":"Montana Delgado", 15 "Text to say":"psum dolor sit amet. Lorem ipsum dolor sit ame" 16 }, 17 { 18 "Roleplayer Number":"3", 19 "Name":"Dianne Mcbride", 20 "Text to say":"olor sit amet. Lorem ipsum" 21 }, 22 { 23 "Roleplayer Number":"4", 24 "Name":"Xena Lynch", 25 "Text to say":"us est Lorem ipsum dol" 26 } 27]
Array of classes to find a specific table using this class. Default is null
/
undefined
.
<th></th>
headings and corresponding <td></td>
cells, but also
taking care of rowspan and colspan. It can give useless or weird results
on tables that have complex structures
(such as nested tables) or multiple headers (such as on both X and Y axis).Find here a list of examples on how to use the library. More examples can be found in the examples folder or in the test folder
1import {tabletojson} from 'tabletojson'; 2const tablesAsJson = tabletojson.convert(html); 3const firstTableAsJson = tablesAsJson[0]; 4const secondTableAsJson = tablesAsJson[1];
1import {tabletojson} from 'tabletojson'; 2tabletojson.convertUrl('https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes', function (tablesAsJson) { 3 console.log(tablesAsJson[1]); 4});
1import {tabletojson} from 'tabletojson'; 2const url = 'http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating'; 3tabletojson.convertUrl(url) 4.then(function(tablesAsJson) { 5 const standardAndPoorRatings = tablesAsJson[1]; 6 const fitchRatings = tablesAsJson[2]; 7});
1import {tabletojson} from 'tabletojson'; 2import {Parser} from 'json2csv'; 3const url = 'http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating'; 4tabletojson.convertUrl(url).then(function (tablesAsJson) { 5 const fitchRatings = tablesAsJson[2]; 6 const json2csvParser = new Parser({ 7 fields: ['Country/Region', 'Outlook'], 8 }); 9 const csv = json2csvParser.parse(fitchRatings); 10 console.log(csv); 11 /* Example output 12 "Country/Region","Outlook" 13 "Abu Dhabi, UAE","Stable" 14 "Albania","Stable" 15 "Andorra","Negative" 16 "Angola","Stable" 17 "Argentina","Negative" 18 "Aruba","Stable" 19 "Australia","Stable" 20 "Austria","Negative" 21 "Azerbaijan","Positive" 22 ... 23 */ 24});
Improvements, fixes and suggestions are welcome.
You can find basic tests in the test folder. The library has been implemented to be used straight forward way. Nonetheless there are some edge cases that need to be tested and I would like to ask for support here. Feel free to fork and create PRs here. Every bit of help is appreciated.
For more usage examples have a look in the examples folder that shows usage and would be a good start.
If you submit a pull request, please add an example for your use case, so I can understand what you want it to do (as I want to get around to writing tests for this and want to understand the sort of use cases people have).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More