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

@sheknows/frisbee

v0.2.0

Published

Data collection transport library

Downloads

171

Readme

Frisbee

Frisbee is a small cross-browser (IE10+) data collection library. It incorporates a queue and a HTTP client. You define endpoint to hit and keep adding data to Frisbee. Frisbee takes care of the rest.

Getting started

Load Frisbee

<script src="/frisbee.js"></script>

Instantiate Frisbee

var frisbee = new window.Frisbee({
  namespace: 'ns',
  url: 'http://foo/bar'
})

Now add some data to it.

frisbee.add(1)
frisbee.add(2)
frisbee.add(3)
frisbee.add(4)
frisbee.add(5)
frisbee.add(6)

Frisbee fills the queue with data until maxItems is reached (5 by default). At that point, Frisbee removes first 5 items from the queue and POSTs them to the options.url. In this example, Frisbee will POST http://foo/bar with the following request payload:

{
  "payload": [1, 2, 3, 4, 5],
  "meta": {
    "namespace": "ns",
    "id": "<instance-specific-uuid>"
  } 
}

6th item (now 1st) will wait until 4 more are added until another POST. Structure of the request payload can be changed using getRequestData function. More info below.

Let's add 1 more item.

frisbee.add(1)

Now we have two items waiting. But let's assume that in your app lifecycle at some point(s) you must ensure that the entire queue is drained and POSTed. We can use

frisbee.sendAll()

This will POST http://foo/bar

{
  "payload": [6, 1],
  "meta": {
    "namespace": "ns",
    "id": "<instance-specific-uuid>" 
  } 
}

Another use-case for sendAll method would be setting a timer to periodically POST data regardless of the maxItems criteria.

Options

{
  // Number of items in the queue to reach when the request is made
  // Default: 5
  maxItems: Number, 

  // HTTP verb to use for requests
  // Default: 'POST'
  method: String,

  // URL to hit
  // Default: undefined
  url: String,

  // HTTP headers to include
  // Default: { 'Content-type': 'application/json; charset=utf-8' }
  headers: Object,

  // Namespace
  // Default: undefined
  namespace: [String, Number, Object],

  // Transform request payload before the request.
  // Runs before every request. This method needs to return a truthy value for request to happen.
  // See example in example/scroll.js
  // Default: 
  //   function (data, meta) {
  //     return JSON.stringify({
  //       payload: data,
  //       meta: meta
  //     })
  //   }
  getRequestData: Function
}

Gotchas

Use getRequestData wisely

Mutating data

Because you have access to data array (of currently emptied queue data), you could append some extra data through this modifier that Frisbee does not know about. Keep in mind that mutating data will have no effect on subsequent calls to this function since every request works with a fresh set of (different) data.

Mutating meta

Mutated meta object however will carry on for all subsequent getRequestData calls. Use that your (dis)advantage.

Must return truthy value

Because request will fire only if this method returns a truthy value, it opens up interesting possibilities. For example, if you want to bundle multiple namespaces into one request, you could create a main frisbee instance to talk to API and bundle several different namespaces while other Frisbee (namespace-specific) instances would be used as queues and never talk to the API, just to the main API Frisbee instance.