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

hypercache

v0.2.0

Published

Simple but powerful caching.

Downloads

15

Readme

Hypercache Build Status codecov

Simple but powerful caching.

Hypercache caches async db operations and gives you the abbility to get things by id or search the database completly sync and with speeds otherwise impossible.

Why hypercache?

  • Fast

  • Zero-Dependencies

  • 100% Test Coverage

Usage

new Hypercache(fnc, options)

  • fnc: A function that is called as fnc(cb)
    • cb(err, res)
    • err: The error that occured, if any
    • res: An array of objects
  • options
    • name: An optional name. If not provided the name will be guessed based on the function
    • keys: A list of unique properties like ["id"]
    • sets: A list of non-unique (also array) properties like ["aliases"]
    • interval: The interval to refresh in ms (default 2500)
    • manual: This will disable the fnc and interval and will expose an update function that is called as update(res)
    • sync: A hypercache to sync with. This will override the call for fnc to fnc(opt.sync.getAll(), cb) and disable the interval.

Events

ready: Emitted when the first update occurs

update: Emitted when an update occurs

error: Emitted when a function without a callback throws an error

Methods

getAll(): Returns an array of all elements

getMap(name): Returns the id->object map for key name

getBy(id, value): Returns an object with [id]==value

getSetMap(name): Returns the id->set map for key name

getSet(id, value): Returns an array with [id]==value || [id].indexOf(value)

search(str): Searches through all keys and returns the first with [key]==str

searchSets(str): Seracher through all sets and returns the first with [key]==value || [key].indexOf(value)

Examples

Fetch and cache data from mongoDB

const cache = new Hypercache(cb => Users.find({}, cb), {
  keys: ["id", "username"],
  sets: ["aliases"]
})
cache.once("ready", () => {
  cache.getBy("username", "mkg20001") // {username: "mkg20001", id: "1234", aliases: ["mkg", "krüger"], ...}
  cache.search("1234") // {username: "mkg20001", id: "1234", aliases: ["mkg", "krüger"], ...}
  cache.searchSets("mkg") // {username: "mkg20001", id: "1234", aliases: ["mkg", "krüger"], ...}
})