contribution

GitHub contribution streak & stat fetcher with zero dependencies

Usage no npm install needed!

<script type="module">
  import contribution from 'https://cdn.skypack.dev/contribution';
</script>

README

Contribution

🗓 GitHub contribution streak & stat fetcher with zero dependencies

build Coverage Downloads Version License Style semantic-release

Install

$ npm install contribution

Usage

import { fetchStats } from 'contribution';

// Callbacks
fetchStats('jamieweavis', {
  onSuccess: data => console.log(data),
  onFailure: error => console.log(error),
});

// Promises
fetchStats('jamieweavis')
  .then(data => console.log(data))
  .catch(error => console.log(error));

// Async/await
async function getContributionData() {
  try {
    const data = await fetchStats('jamieweavis');
    console.log(data);
  } catch (error) {
    console.log(error);
  }
}

API

fetchStats(username, [options])

Type: Function

Returns: Promise

Resolves: Object

Resolves an object with the following structure:

{
  streak: {
    best: Number,
    current: Number,
  },
  contributions: {
    best: Number,
    current: Number,
    total: Number,
  }
}

username

Type: String

The GitHub username to fetch contribution data for.

options

Type: Object

onSuccess

Type: Function

Parameters: data

Callback function to handle the returned data. Passed a data object which has the same structure as the resolved data object above.

onFailure

Type: Function

Parameters: error

Callback function to handle an error. Passed an error object which corresponds to a HTTP Response with error.statusCode etc.

enableCors

Type: Boolean

Default: false

Whether to proxy the request through the cors-anywhere API to enable fetching data x-origin. Set this option to true if you are using contribution through the browser.

Related

  • streaker - 🐙 GitHub contribution streak & stat tracking menu bar app
  • streaker-cli - 🐙 GitHub contribution streak & stat tracking CLI app