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

@crossfoam/data

v1.0.3

Published

Data handling module

Downloads

4

Readme

crossfoam-dev-data

Data handling module

General Data Structure

Web-Extensions can only use key-value storage for persistent data storage, due to the time it takes to acquire all the network information we need to rely on persisent storage and cannot use more fancy stuff. So it is basically all about hash-tables and smart key structures. The following json describes the structure of the extension's storage:

storage:{
  # The services are used to temporarily store the data gathered from a service, this data is later transformed into network data, stored under the networks key 
  services:{
    TWITTER:{
      users:[
        CENTRALNODE
      ],
      analysis:{
        # CENTRALNODE is the id of the user/account/xx used to build a network. The uuid is added to allow users to create multiple networks from the same user, e.g. at different timestamps
        CENTRALNODE-uuid:{
          centralnode:{
            id:string,
            name:string,
            handle:string,
            image:string
          },
          nodes:{
            node-ID:{
              name:string,
              handle:string,
              image:string,
              friends:[
                IDs
              ],
              followers:[
                IDs
              ],
            },
            ...
          },
          network:{
            nodes:[
              {
                id:integer,
                name:string,
                image:string,
                type:integer(0:normal|1:proxy),
                cluster:integer(-1:no cluster|1:...)
              },
              ...
            ],
            edges:[
              {
                from:integer(nodes-id),
                to:integer(nodes-id),
                strength:float,
                type:integer(0:normal|1:proxy)
              },
              ...
            ]
          },
          clusters:{
            clusterType_N:{
              clusterID:{
                name:,
                color:
              },
              ...
            },
            ...
          }
        },
        ...
      }
    }
  },
}

through browser.storage.local.get we can only get top level elements of our objects, this means everything is being loaded into memory even if we specifically know what we want, therefore, we use a flattened tree that works as follows:

storage.services.TWITTER.analysis.CENTRALNODE-uuid.centralnode 

# is being turned into

storage.services--TWITTER--analysis--CENTRALNODE-uuid--centralnode

At a certain depths the remaining content is then stored as objects, the following flat links are provided:

  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--centralnode
  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--nodes--nodeID
  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--proxies--proxy-ID
  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--network--nodes
  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--network--edges
  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--clusters--clusterID

The above makes it hard to find out what we actually have in store, therefore, we introduce lists, which keep track:

  • storage.serviceList > names of services and created CENTRALNODEs

  • storage.networkList > created CENTRALNODEs

  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--nodeList

  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--proxyList

  • storage.services--TWITTER--analysis--CENTRALNODE-uuid--clusterList

TODO: In order to reduce the storage size, the keys are reduced:

services > s analysis > a centralnode > c nodes > n network > nw users > u

Storage Dictionary

In order to allow the system to check if a user has already been scraped, it contains an additional list of userids and their respective CENTRALNODE-uuid references

  • storage.services--TWITTER--networks--USERID > [{uuid:uuid, call_count: number, state: queuing|waiting|running|completed}]

Queuing

There are many things that need to be queued, normally we could use calbacks and promises to simple chain everything together. But we have to take one important thing into take in account, the browser might be closed or the internet connection might be turned off, leaving us with an incomplete queue. Therefore, the extension has a queue module, which knows what to do next. The backbone of the queue is also stored in the local storage, allowing us to retrieve and pick up the queue when ever something unfortunate happens.

The queue is an object, each key represents a function call, holding an array of requests to that function containing parameters

startTime allows sorting the calls by time of first initiation, while some functions will lead to arrows, if the error is handled properly the function adds itself back to the queue for another try. If another scrape was initiated in the meantime, this will push this re-call back to end of the queue, meaning the first scrape cannot finish before the second scrape is finished. In order to overcome this, the queue is re-sorted by the original initiation time.

uniqueID connects various queue calls to one scrape process, thereby, allowing for the removale of proceses and all queue calls. As queue calls might be pending, there is another dicitionary for removed uniqueIDs, skipping future adding of connected calls to the queue.

storage:{
 queue:{
   networkAnalysis:[
     [
       [
         param-1,
         param-2,
         param-3
       ],
       startTime,
       uniqueID
     ],
   ]
 }
}

Clusters (Bubbles)

For the network visualisation and analysis, the networks are stored within the above structure, but beyond that, the modification of html pages needs to quickly find out if a user exists in a cluster, therefore user's association with a cluster is store

storage:{
  services:{
    TWITTER:{
      nodes:{
        USERID:[
          [CENTRALNODE-uuid, CLUSTER-KEY],
          ...
        ],
        ...
      }
    },
    ...
  }
}

The corresponding flat keys are:

  • storage.services--TWITTER--nodes--USERID