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

simple-github-api

v1.2.1

Published

A wrapper for the github api to ease requesting files, directory information from a repository

Downloads

6

Readme

simple-github-api

npm version Build Status Coverage Status

This is a simple wrapper for the GitHub API to ease requesting files, directory information from a repository.

Basic Usage:

# To download and install
npm install --save simple-github-api
const API = require('simple-github-api')

let instance = new API({
   // https://github.com/blog/1509-personal-api-tokens
   token: "Some valid OAUTH key issued by github",

   // choose your repo, or you can omit this option and set it later
   repo: "myProject",

   // the username/owner of the repo(s)
   username: "markzuckerberg"
})

instance.get('/some/path')
   .then(metafile => {
      // returns a file object or if
      // a directory a list of file objects
      console.log(metafile)
   })
   .catch(err => {
      throw err
   })

// OR

instance.getContents('some/file/path')
   .then(file => {
      // contains actual file
      console.log(file)
   })

API

const API = require('simple-github-api')

Constructors

The new keyword is required to create an instance of the API object.

It is recommended to get an OAUTH key issued for your application and instantiate with that token.

let instance = new API(
   {
      token: "A valid token"
   })

The default object however doesn't require any config.

// results in a warning.
// If you do > 60 requests per day
// you will get a 401 error for api requests.
let instance = new API()

You can also pass in basic auth credentials, and a repository.

// all valid options you can pass in
options = {
   username: "jeff",
   pw: "secret",
   repo: "sweetProject",

   // token will override basic auth if provided
   token: "OAUTHToken"
}

Main Features

The basic interface below is unlikely to change, although further features may be added later. For all of the below path is a string.

Interface | Description --------- | ---------- .get(path) | Returns the fileObject or directory for the relevant file. Takes a string relative path, and requires the repo and user to be set. .getUrl(path) | Returns the current url formed for the request. Mainly called internally. .getContents(path) | Returns the file contents directly, decoded and ready to use. .decode(encodedFile) | Decodes a file object in base64Unicode.

Configuration

// sets/update a new repo
instance.repo = "NewRepo"

// sets/update user
instance.user = "newUser"

// returns the underlying axios instance
// which you can configure as you so desire
// More on axios here https://github.com/axios/axios
let axios = instance.axios

Credits

Project built leaning heavily on the simplicity of the axios api.

License

MIT