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

github-release-stats

v1.0.2

Published

Library for fetching the GitHub release download count and other statistics

Downloads

7

Readme

GitHub Release Stats

Build and test Codecov NPM License

Description

GitHub Release Stats is a JavaScript library written in TypeScript for fetching the GitHub release download count and other statistics.

It can be used in several ways:

This library also supports the GitHub API pagination out of the box.

Usage

Using as a command-line tool

Installation

npm i -g github-release-stats

Now you can run ghstats in your command line interpreter.

Syntax

ghstats [owner] [repo] [tag] [options]
ghstats [owner/repo] [tag] [options]

Parameters

| Parameter | Description | | --------- | ----------------------------------------------------------------------- | | owner | Repository owner. If not present, you will be prompted for the input. | | repo | Repository name. If not present, you will be prompted for the input. | | tag | Release tag name. If not present, prints the total number of downloads. |

Options

| Option | Description | ---------------- | ---------------------------------------------------- | | -d, --detail | Print detailed statistics for each release | | -q, --quiet | Print only resulting numbers and errors (quiet mode) | | -l, --latest | Print statistics for the latest release | | -h, --help | Print help message |

Environment Variables

| Environment Variable | Description | | -------------------- | ------------------------------------------------------ | | GITHUB_TOKEN | GitHub personal access token. Read more |

Examples

ghstats atom atom            # Print download count for all releases.
ghstats atom/atom            # Print download count for all releases (alt. syntax).
ghstats atom atom -q         # Quiet mode (print only numerical result or errors).
ghstats atom atom -d         # Print detailed description for each release.
ghstats atom atom -l         # Print download count for the latest release.
ghstats atom atom -l -q      # Print download count for the latest release (quiet mode).
ghstats atom atom -l -d      # Print detailed description for the latest release.
ghstats atom atom v1.0.0     # Print download count for the the "v1.0.0" release.
ghstats atom atom v1.0.0 -q  # Print download count for the the "v1.0.0" release (quiet mode).
ghstats atom atom v1.0.0 -d  # Print detailed description for the "v1.0.0" release.
ghstats                      # Get repository owner and name from the user input.
ghstats -h                   # Print help message.

Using as a Module

You can use this library in both Node.js and browser environments. In the latter case, you can use bundlers such as Webpack and Parcel.

Installation

npm i github-release-stats

Constructor

GithubStats(repoOwner: string, repoName: string, token?: string)

| Parameter | Description | Required | | ----------- | ------------------------------------------------------ | -------- | | repoOwner | Repository owner | Yes | | repoName | Repository name | Yes | | token | GitHub personal access token. Read more | No |

Methods

| Method | Description | Returns | | ---------------------------------- | ------------------------------------------------------------------------- | -------------------------- | | getAllReleases() | Fetch all releases | Promise<GithubRelease[]> | | getLatestRelease() | Fetch the latest release | Promise<GithubRelease> | | getRelease(tag: string) | Fetch a single release by the specified tag | Promise<GithubRelease> | | getTotalDownloads() | Fetch the total number of release downloads for the whole repo | Promise<number> | | getLatestReleaseDownloads() | Fetch the number of downloads for the latest release | Promise<number> | | getReleaseDownloads(tag: string) | Fetch the number of downloads for a single release by the specified tag | Promise<number> |

Example of a GithubRelease object: https://api.github.com/repos/atom/atom/releases/latest

Example

// ES Module:
import { GithubStats } from 'github-release-stats';

// CommonJS Module:
const { GithubStats } = require('github-release-stats');
const gh = new GithubStats('atom', 'atom');

gh.getTotalDownloads().then(count => {
  console.log('Total downloads: ' + count);
}).catch(error => {
  console.error(error.message);
});

API Limits

By default, GitHub API allows you to make up to 60 requests per hour. You can increase this limit by specifying your personal access token which can be created here.

  • Store your token in the GITHUB_TOKEN environment variable (works in CLI and Node.js environment)
  • Pass your token to the GithubStats constructor (works in Node.js and browser environments)

License

MIT License

You are free to use, modify, distribute (including commercial purposes) as long as you credit the original author and include the license text.