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 🙏

© 2025 – Pkg Stats / Ryan Hefner

level-hookdown

v3.1.2

Published

Simple leveldb hooks

Downloads

83

Readme

level-hookdown

Simple levelup hooks implemented using instance method override of arbitrary levelups.

npm install level-hookdown

level badge npm Build Status dependencies Status devDependencies Status

Usage

var hook = require('level-hookdown')
var mem = require('level-mem')  // or 'level' or other levelup factory
var mdb = mem()
var db = hook(mdb)

function prehook (operation, cb) {
  console.log('this should run before the db operation')
  console.log(operation)
  cb()
}

function posthook (operation, cb) {
  console.log('this should run after the db operation')
  console.log(operation)
  cb()
}

db.prehooks.push(prehook)
db.posthooks.push(posthook)

db.put('beep', 'boop', function (err) {
  if (err) throw err
  db.del('beep', function (err) {
    if (err) throw err
    db.batch([
      { type: 'put', key: 'father', value: 'gloop' },
      { type: 'put', key: 'another', value: 'heep' }
    ], function (err) {
      if (err) throw err
      console.log('done')
    })
  })
})

API

hookdb = hook(db, [options])

Returns a levelup instance that executes a series of pre and post hook functions before put, del, and batch method calls. Composes well with mafintosh/subleveldown. Conflicts with dominictarr/level-sublevel.

The following options can be set when wrapping a level with hook:

{
  type: 'parallel' | 'series' | 'limit',
  limit: 5,
  protectHook: false
}
  • The type determines if the hook functions are run in series, parallel or parallel-limit. Default is parallel.
  • The limit option is passed to run-parallel-limit when type is set to limit. The default is 5.
  • protectHook performs a deep copy on the operation array in batches to preserve values if the levelup mutates them (like subleveldown does).

Hooks

hookdb.prehooks

An array of hook functions that are run before put, del, and batch method calls to the hookdb instance. If a hook function in the prehook array returns an err object to its callback, the originating put, del or batch operation will not be run on the contained db that hookdb is wrapping. A prehook veto convetion could be built on top of this behavior via error handling and retry.

hookdb.posthooks

An array of functions that are run after sucessful put, del, and batch method calls on the wrapped db instance inside a hookdb instance.

hookFn(operation, callback)

Hook functions receive an operation object that describes the level operation and a callback function.

hookdb.prehooks and hookdb.posthooks are arrays that you can add, rearrange, and delete hook functions from using standard array methods like hookdb.prehooks.push(fn) and hookdb.posthooks.pop(fn).

operation

The operation argument can contain an object that looks like:

  • {type:'put', key: 'key', value: 'value', opts}
  • {type: 'del', key: 'key', opts}
  • {type: 'batch', array: [operationArray], opts}

The opts object in the level operation object are the options that get passed through to the wrapped level.

See Also

This module is basically an alternative implementation of:

but aimed at a subleveldown workflow. These were also influential: