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

marvel-comics-api-stream

v1.1.1

Published

streams Marvel API data

Downloads

8

Readme

marvel-comics-api-stream

stable

Streams paginated Marvel Comics API data. By default, streams until no more pages remain, but can be configured to stream a limited number of pages.

For a lower level interface, see marvel-comics-api.

Install

npm install marvel-comics-api-stream --save

Example

var marvel = require('marvel-comics-api-stream')

// stream in 3 pages of data
marvel('comics', {
  publicKey: conf.publicKey,
  privateKey: conf.privateKey,
  pages: 3
}).on('info', function (ev) {
  console.log('%s\n', ev.attributionText)
}).on('data', function (comic) {
  console.log(comic.title)
}).on('end', function () {
  console.log('Finished!')
})

Result:

Data provided by Marvel. © 2015 MARVEL

Ant-Man: So (Trade Paperback)
Uncanny X-Men (2013) #600
Brilliant (2011) #6
Secret Wars (2015) #6
Future Imperfect (2015) #5
Agent Carter: S.H.I.E.L.D. 50th Anniversary (2015) #1
Daredevil (2014) #18
E Is for Extinction (2015) #4
Figment 2 (2015) #1
...
...
...
Finished!

Usage

NPM

stream = marvelStream(api, opt)

Streams Marvel data from the given api entry point (like 'characters' or 'comics'). The stream emits 'data' events for each element in the response's data.results array.

Options:

  • publicKey (string)
    • required - your public API key
  • privateKey (string)
    • required - your private API key
  • pages (Number|any)
    • if specified and a number, no more than that many pages of content will be streamed
    • otherwise, if a non-number is passed, assumes all content is desired, and streams until no pages are left

The other options are passed to marvel-comics-api, like query and timeout.

Once all data has been streamed, or once we've hit our desired number of pages, emits an end event.

events

stream.on('info', fn)

Triggered once before any other events, providing the following:

{
  copyright: String,       // copyright detail
  attributionText: String, // attribution detail
  attributionHTML: String, // attribution detail
}

stream.on('page', fn)

The stream emits a 'page' for each request.

{
  page: Number,   // current page index
  offset: Number, // current offset index into the results
  limit: Number,  // the resulting limit for this page
  count: Number,  // the number of results in this page
  total: Number   // total number of results across all pages
}

stream.on('data', fn)

After 'page' is emitted, that page will emit a 'data' event for each of its entity results (e.g. a comic book or character). See Entity Types for details on their structure.

stream.on('error', fn)

The stream emits a 'error' event if one of the requests failed; e.g. incorrect API key, server timeout, or an invalid referrer.

running tests

To run tests, you will need a Marvel Developer account. Once you have API keys, copy them into a file in .apikey.json that looks like this:

{
  "privateKey": "egadg545151232d02ea0b9asdfasdfd5699a",
  "publicKey": "badsg1cbadsggagafdh0"
}

See Also

License

MIT, see LICENSE.md for details.