npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-covid19-json-fetcher

v1.5.0

Published

Fetches covid-19 data in json format using Johns Hopkins CSSE 2019 Novel Coronavirus COVID-19 data as source

Downloads

35

Readme

Simple COVID-19 JSON Fetcher

🦠🦠🦠🦠

Provides a helper function for fetching Johns Hopkins CSSE's COVID-19 data formatted by countries and their provinces and states. Fetcher function will automatically fallback to previous date if target date's data is not ready.

Demo

Code Sand Box Demo

Install

npm install simple-covid19-json-fetcher

Usage

import covid19Fetcher from 'simple-covid19-json-fetcher'

;(async () => {
  const covidCountries = await covid19Fetcher(new Date())
})()

API

const covidCountries = await covid19Fetcher(targetDate, options)

Options

{
  // Setting `fetchRaw` to true will cause the function to
  // return the country data unformatted
  // (keys will still be camelCased)
  fetchRaw: false,

  // Passing an `entryMutator` function enables entries to be manually
  // modified before they are being processed.
  // Useful for renaming country or state names etc.
  entryMutator: null
}

Data Format

[
  {
    name: 'US',
    confirmed: 53740,
    deaths: 706,
    recovered: 348,
    active: 52686,
    latitude: 38.084445254260665,
    longitude: -91.34862805287611,
    states: [
      {
        name: 'Alabama',
        confirmed: 242,
        deaths: 0,
        recovered: 0,
        active: 242,
        latitude: 32.53952745,
        longitude: -86.64408227
      },
      ...more states

    ]
  },
  ...more countries

]

Entry Mutator Example

entryMutator is a function that is passed to a map function at the beginning of the data processing. It can be used to manipulate the COVID-19 data before its being processed.

const covidCountries = await covid19Fetcher(new Date(), {
  entryMutator: entry => {
    if (entry.countryRegion === 'US') {
      return { ...entry, countryRegion: 'United States' }
    }
    return entry
  }
})

const us = covidCountries.find(x => x.name === 'United States') // found!

entryMutator can be used for filtering. Only the returned entries are included, others are discarded:

const usIdahoAndUtah = await covid19Fetcher(new Date(), {
  entryMutator: entry => {
    if (entry.provinceState === 'Idaho' || entry.provinceState === 'Utah') {
      return entry
    }
  }
})

// usIdahoAndUtah ->
[
  {
    "name": "US",
    "states": [
      {
        "name": "Idaho",
        "confirmed": 146,
        "deaths": 3,
        "recovered": 0,
        "active": 143,
        "latitude": 43.4526575,
        "longitude": -116.24155159999998,
        "lastUpdate": "2020-03-26 23:48:35"
      },
      {
        "name": "Utah",
        "confirmed": 396,
        "deaths": 1,
        "recovered": 0,
        "active": 395,
        "latitude": 38.35657051,
        "longitude": -113.2342232,
        "lastUpdate": "2020-03-26 23:48:35"
      }
    ],

    // The following items will contain the combined data of Idaho and Utah. 
    "confirmed": 542,
    "deaths": 4,
    "recovered": 0,
    "active": 538,

    "latitude": 41.851358595810815,
    "longitude": -111.79096034054051,
    "lastUpdate": "2020-03-26 23:48:35"
  }
]

Each entry passed to the entryMutator has the following properties:

{
  "fips": "16087",
  "admin2": "Washington",
  "provinceState": "Idaho",
  "countryRegion": "US",
  "lastUpdate": "2020-03-26 23:48:35",
  "lat": "44.45275475",
  "long": "-116.78476880000001",
  "confirmed": "0",
  "deaths": "0",
  "recovered": "0",
  "active": "0",
  "combinedKey": "Washington, Idaho, US"
}

Note, that the data is fetched from Johns Hopkins CSSE's COVID-19 repository and may change at any time.