Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ghdl

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ghdl

get download info of a github release by just providing the name of a github repository

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

#ghdl

travis npm version

ghdl (github download) is a node module and command line program that searches github repositories using the github api for a given repository name and returns download info of all tags of the given repo name if it is a real github repo with valid release(s) that have some file(s) to download because otherwise the api returns empty assets for the repo.

You don't need to know the name of the user or the owner; just provide the name of a repository. For the most cases that ghdl finds only one match, it returns an object with download info of all tags of the given repo (see details below); however, in cases where there is more than one repo with the same name and with real releases (tags), it returns an array of objects that each object contain download info of each repo.

###install

use the command line interface

Please run npm install -g ghdl. If you encounter with a problem or getting EACCES error, read fixing-npm-permissions.

use programmatically

run npm install ghdl

###api token

In order to make authenticated requests to github api, we need some sort of authorization method. Since we are not dealing with sensitive data and basically all data is public data that everyone can send an http request to the api and get it on their browser or on other platforms; however, ghdl uses personal access token which according to github docs works the same as OAuth tokens and can easily be generated on GitHub.

You can use a new access token by setting the environment variable GITHUB_TOKEN.

###command line usage

get download count of only the latest tag (default)

ghdl <repository name>

example: ghdl kubernetes

get download count of all tags

ghdl <repository name> -a

example: ghdl kubernetes -a

show the help menu

ghdl -h

show the module version

ghdl -v

###sample output

download info of only the latest tag

alt text

download info of all tags

alt text

###api

ghdl(repo_name, callback)

  • repo_name {String} -- repository name to get its download info
  • callback {Function} -- gets two arguments (err, repo)
    • err is an Error object (you get the error message by err.message)
    • repo is
      • object if the given name matches only one real repo with valid tags
      • array of objects if the name matches more than one repo with real tags
      • null if no matches found

each result object has these properties:

{
  url: '',
  tags: [{
    tagname: '',
    published_at: '',
    files: [{
      filename: '',
      updated_at: '',
      download: 0
    }]
  }]
}

The latest tag is the first element of result object's tags array; that is, repo.tags[0].

###api usage

Based on the search result, ghdl returns:

  • null -- if no matches found.
  • object -- if only one repo found
  • array of objects -- if more than one repo with valid tags found

get download info of all tags


const ghdl = require('ghdl');

var repo_name = 'githubRepoName';

ghdl(repo_name, (err, result) => {
  if (err) {
    console.error(err.message);
  }
  if (result && !Array.isArray(result)) {
    // only one repo found, return an object
    console.log(result.url);
    console.log(result.tags);
  } else if (result && Array.isArray(result)) {
    // more than one repo found, return an array of objects
    result.forEach((repo) => {
      console.log(repo.url);
      console.log(repo.tags);
    });
  } else {
    console.log(`no github release found for ${repo_name}.`);
  }
});

get download info of only the latest tag


const ghdl = require('ghdl');

var repo_name = 'githubRepoName';

ghdl(repo_name, (err, result) => {
  if (err) {
    console.error(err.message);
  }
  if (result && !Array.isArray(result)) {
    // the latest tag is the first element of result.tags
    var latest_tag = result.tags[0];
    console.log(result.url);
    console.log(latest_tag.tagname);
    console.log(latest_tag.published_at);
    console.log(latest_tag.files);
  } else if (result && Array.isArray(result)) {
    result.forEach((repo) => {
      var latest_tag = repo.tags[0];
      console.log(repo.url);
      console.log(latest_tag.tagname);
      console.log(latest_tag.published_at);
      console.log(latest_tag.files);
    });
  } else {
    console.log(`no github release found for ${repo_name}.`);
  }
});

Enjoy using ghdl.

Keywords

FAQs

Package last updated on 16 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc