covidAPI = {
const URL = `https://covidapi.info/api/v1`
const get = async (...endpoint) => (await (await fetch(`${URL}/${endpoint.filter(e => !!e).join('/')}`)).json())
const getBody = async (...endpoint) => (await (await fetch(`${URL}/${endpoint.filter(e => !!e).join('/')}`)).text())
return {
country: (country, dateStart = false, dateEnd = false) =>
get(...(!dateEnd
? ['country', country, dateStart]
: ['country', country, 'timeseries', dateStart, dateEnd]
)),
global: (dateStart = false, dateEnd = false) =>
get('global', dateStart, dateEnd),
globalTimeseries: (dateStart, dateEnd) =>
get('global', 'timeseries', dateStart, dateEnd),
globalCount: () => get('global', 'count'),
latestDate: () => getBody('latest-date'),
latest: (country = false) => get(...(country ? ['country', country, 'latest'] : ['global', 'latest']))
}
}