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

gh-api-stream

v1.0.3

Published

streams JSON content from a GitHub API

Downloads

4

Readme

gh-api-stream

stable

Streams paginated JSON from a GitHub API.

var api = require('gh-api-stream')

// prints all my follower's usernames
api('/users/mattdesl/followers')
  .on('data', function (follower) {
    console.log(follower.login)
  })

For a non-streamed and browser-friendly alternative, see gh-api.

Install

npm install gh-api-stream

Examples

Below is an example of paging through all 'open' issues in a repo. It parses the JSON by row rather than buffering it all at once. Uses ghauth for easy authentication.

var api = require('gh-api-stream')
var ghauth = require('ghauth')

ghauth({
  configName: 'my-test', 
  scopes: ['user', 'repo']
}, function (err, data) {
  if (err) throw err
  
  api('/repos/mattdesl/budo/issues', {
    query: {
      state: 'open'
    },
    token: data.token,
    rows: true
  }).on('data', function (issue) {
    console.log(issue.title)
  }).on('end', function () {
    console.log("Done!")
  })
})

See test/example.js for another example.

Usage

NPM

stream = ghApiStream(api, [opt])

Returns an object stream that emits 'data' results from the request.

api is a String for the API like '/repositories' or '/orgs/:owner/repos'.

The options:

  • token (String)
    • optional authentication token
  • pages (Number)
    • if specified, will limit the request to no more than N pages. Otherwise streams until we have no remaining pages
  • rows (Boolean|String|Array)
    • if true, parses the JSON in rows, emitting a 'data' event for each row. If false or undefined, it will buffer and emit the entire JSON
    • Strings and Arrays are passed to JSONStream parse path, e.g. '*.user.login'

Other options are passed to got, like query, method and body. Requests use 'https://api.github.com/' as a URL base.

stream = ghApiStream.url(url, [opt])

You can use this to pass a full URL to your API endpoint. The options are the same as above.

var api = require('gh-api-stream')
var stream = api.url('https://my-fancy-github.com/repositories')

See Also

  • gh-api - a non-streamed alternative suitable for the browser
  • gh-got - a related library built on got

License

MIT, see LICENSE.md for details.