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

hyperdb-index-level

v2.0.2

Published

A hyperdb-index backed by LevelDB.

Downloads

10

Readme

hyperdb-index-level

A hyperdb-index backed by LevelDB.

Convenience module for hyperdb that wraps up hyperdb-index with a LevelDB backend.

Usage

var hindex = require('hyperdb-index-level')
var hyper = require('hyperdb')
var level = require('level')
var ram = require('random-access-memory')

var db = hyper(ram, { valueEncoding: 'json' })
var lvl = level('./index')
var idx = hindex(db, lvl, processor)

function processor (node, next) {
  lvl.get('sum', function (err, sum) {
    if (err && !err.notFound) return next(err)
    else if (err) sum = 0
    else sum = Number(sum)

    console.log('sum so far', sum, node.value)
    sum += node.value
    lvl.put('sum', Number(sum), next)
  })
}

var getSum = function (cb) {
  idx.ready(function () {
    lvl.get('sum', function (err, sum) {
      cb(err, sum ? Number(sum) : undefined)
    })
  })
}

db.put('/numbers/0', 15, function (err) {
  db.put('/numbers/1', 2, function (err) {
    db.put('/numbers/2', 8, function (err) {
      getSum(function (err, sum) {
        console.log('the sum is', sum)
      })
    })
  })
})

outputs

sum so far 0 [ 8 ]
sum so far 8 [ 2 ]
sum so far 10 [ 15 ]
the sum is 25

API

var hindex = require('hyperdb-index-level')

var idx = hindex(db, lvl, processorFn)

Creates a new indexer on the hyperdb instance db.

The Level instance lvl is used for storage.

processorFn is called on the latest value of key that gets set, with the function signature processorFn(node, next). node is the next hyperdb node to be processed, and next is called with an optional error to tell the indexer to proceed.

idx.ready(cb)

Registers the callback cb to fire when the indexes have "caught up" to the latest known change in the hyperdb. The cb function fires exactly once. You may call idx.ready() multiple times with different functions.

Tips

If you want to store multiple indexes in one LevelDB, you can partition it with subleveldown so that the indexes can't affect each other.

Install

With npm installed, run

$ npm install hyperdb-index-level

Acknowledgments

Development was sponsored by Digital Democracy.

License

ISC