The covid19.js library can be used to create web applications based off covid19 data. The original data source is the CSSEGISandData/COVID-19 repository by Johns Hopkins CSSE, and leverages the coviddata/covid-api repository for more reliable data formatting.
<script src="covid19.min.js"></script>
<script src='https://collaboratescience.com/covid19/covid19.min.js'></script>
- @returns {object} (summary object with global total cases, deaths, recoveries)
covid.get_global_report()
{cases: 531574, deaths: 24016, recoveries: 123334}
- @param {string} location (choose location)
- @returns {object} (summary object with country total cases, deaths, recoveries)
covid.get_location_report("Wyoming")
{cases: 53, deaths: 0, recoveries: 0}
- @param {string} category (choose between cumulative and new)
- @param {string} type (choose between cases, deaths, and recoveries)
- @param {string} country_or_region (choose country_or_region)
- @returns {object} (time series object for chosen location)
covid.get_time_series("cumulative", "cases", "California")
[
...
{date: "2020-03-21", value: 1364},
{date: "2020-03-22", value: 1646},
{date: "2020-03-23", value: 2108},
{date: "2020-03-24", value: 2538},
{date: "2020-03-25", value: 2998},
{date: "2020-03-26", value: 3899}
]
- @returns {array} (all countries listed in data)
covid.get_all_countries()
[
"Thailand",
"Japan",
"Singapore",
"Nepal",
"Malaysia",
"Canada",
"Australia",
"Cambodia"
...
]
- @returns {array} (all regions listed in data)
covid.get_all_regions()
[
"Washington",
"New York",
"California",
"Massachusetts",
"Diamond Princess",
"Grand Princess",
"Georgia"
...
]
- @param {string} country (choose country)
- @returns {boolean} (true/false whether chosen country has states)
covid.check_if_country_has_region("Italy")
false
- @returns {array} (all available dates in data)
covid.get_available_dates()
[
...
"03-12-2020",
"03-13-2020",
"03-14-2020",
"03-15-2020",
"03-16-2020",
"03-17-2020",
"03-18-2020",
"03-19-2020"
]
- @returns {array} (array of objects with all country and region pairs)
covid.get_countries_and_regions()
[
{country: "China", region: "Hubei"},
{country: "United States", region: "New York"},
{country: "France", region: "France"},
{country: "United States", region: "New Jersey"},
{country: "United Kingdom", region: "United Kingdom"},
{country: "United States", region: "California"}
...
]
- @param {string} region (choose region)
- @returns {string} (name of country associated with region)
covid.get_country_from_region("Faroe Islands")
"Denmark"
- @param {string} country (choose country)
- @returns {array} (all regions associated with country)
covid.get_regions_from_country("Canada")
[
"Alberta",
"British Columbia",
"Diamond Princess",
"Manitoba",
"New Brunswick",
"Newfoundland and Labrador",
"Nova Scotia"
...
]
- @param {string} country (choose country)
- @returns {string} (country code associated with country)
covid.find_code_by_country("Dominican")
"DO"
- @param {string} region (choose region)
- @returns {string} (country code associated with region)
covid.find_code_by_region("Gibraltar")
"GB"
- @param {string} location (choose location)
- @returns {boolean} (true/false depending on whether location is in data)
covid.check_if_location_in_data("Los Angeles")
- @param {string} country_or_region (choose country_or_region)
- @returns {boolean} (true/false depending on whether location is a country)
covid.check_if_country("Italy")
true
- @param {string} country_or_region (choose country_or_region)
- @returns {boolean} (true/false depending on whether location is a region)
covid.check_if_region("Canada")
false
- @param {string} location (choose location)
- @returns {string} (image URL of country or region flag)
covid.get_country_flag("Bulgaria")
"https://collaboratescience.com/corona/flags/bg.png"
Reach out to Sean McClure if you need assistance or would like to see additional useful functions added to this library.
If you encounter issues with the consistency of results returned by this library please raise an issue on this repo.