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

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

#ghdl

travis npm version

ghdl (github download) is a node module 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.

If you are looking for a convenient front-end to get download info af a github release on your terminal and don't want to deal with the api, you can use ghdl-cli.

###install

npm install ghdl

###api

ghdl(repo_name, opts, callback)

  • repo_name {String} -- repository name to get its download info
  • opts {Object} -- gh-got options
    • the most important one is opts.token, which is the GitHub access token and can be set globally with GITHUB_TOKEN environment variable
  • 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

In order to make authenticated requests to github api, the GitHub access token can be used that works the same as OAuth tokens and can easily be generated on GitHub. It can be set globally with GITHUB_TOKEN environment variable.

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');

const opts = {
  token: 'foo',
  headers: {
    'user-agent': 'https://github.com/mawni/ghdl'
  }
};

var repo_name = 'githubRepoName';

ghdl(repo_name, opts, (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');

// use the default user-agent (https://github.com/mawni/ghdl)
// just provide the github token

ghdl('githubRepoName', {token: 'foo'}, (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