Skip to content

πŸ—“ GitHub contribution streak & stat fetcher with zero dependencies

License

Notifications You must be signed in to change notification settings

jamieweavis/contribution

Repository files navigation

Contribution Project Logo

πŸ—“ GitHub contribution streak & stat fetcher with zero dependencies

build Coverage Downloads Version License Style semantic-release

Contents

Installation

Contribution can be installed from the command line with npm:

$ npm install contribution

Usage

Import fetchStats from Contribution using CommonJS require or ES Module import:

// CommonJS require
const { fetchStats } = require('contribution');

// ES Module import
import { fetchStats } from 'contribution';

Contribution can be used with callbacks, promises or async/await:

// 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

License

This project is licensed under the MIT License - see the LICENSE.md file for details.