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

level-merged-stream

v0.0.2

Published

[![Build Status](https://travis-ci.org/coinative/level-merged-stream.svg?branch=master)](https://travis-ci.org/coinative/level-merged-stream) [![Coverage Status](https://img.shields.io/coveralls/coinative/level-merged-stream.svg)](https://coveralls.io/r/c

Downloads

6

Readme

level-merged-stream

Build Status Coverage Status

A LevelUP plugin to merge multiple ranges into a single sorted stream using a subkey for ordering. Useful when doing range queries against multiple key-based secondary indexes. Supports standard LevelUP stream options and naïve pagination via a skip option.

Install

Not currently hosted on npmjs.org. Take this module as a git dependency via:

npm install level-merged-stream

Usage

Given a LevelUP instance db:

var mergedStream = require('level-merged-stream');

db = mergedStream(db);

API

  • db.createMergedReadStream()
  • db.createMergedKeyStream()
  • db.createMergedValueStream()

db.createMergedReadStream([options])

As per db.createReadStream() but with the following additional options:

  • 'ranges' (array): The start/end ranges as you'd provide to createReadStream. Each range is streamed and merged according to the value privided by subkey. Each range must be ordered by subkey, i.e. any range prefix must be constant for the entire range for overall ordering to be consistent.

  • 'subkey' (function, default: identity): Selects the subkey from the key that is used for ordering the results.

  • 'comparator' (function, default: primitive comparison): A subkey comparator function if primitive comparison is insufficient, .e.g. for Buffers or custom keys.

  • 'dedupe' (boolean/function, default: false): If true, when two or more subkeys are considered equal, only the first result will be streamed. The key and/or value returned could come from any underlying range stream. If a function, it should return true if two keys passed are considered equal for deduplication purposes.

  • 'skip' (number, default: 0): The number of results to skip in the merged stream. Useful for pagination when also using limit.


db.createMergedKeyStream([options])

As per db.createKeyStream() this streams only the keys.


db.createMergedValueStream([options])

As per db.createValueStream() this streams only the values.


Example

examples/readme.js:

var path = require('path');
var level = require('level');
var mergedStream = require('level-merged-stream');

var location = path.join(__dirname, '/.db');
var db = level(location);
db = mergedStream(db);

db.batch()
  .put('a1', '1')
  .put('b2', '2')
  .put('c3', '3')
  .put('d4', '4')
  .put('a5', '5')
  .put('b6', '6')
  .put('c7', '7')
  .put('d8', '8')
  .write(function () {
    db.mergedReadStream({
      // Only stream the 'a's and 'c's
      ranges: [
        { start: 'a', end: 'b' },
        { start: 'c', end: 'd' }
      ],
      // Ignore the first character for sorting
      subkey: function (key) {
        return key.slice(1);
      },
      skip: 1,
      limit: 2
    })
      .on('data', console.log)
      .on('end', function () {
        db.close(function () {
          level.destroy(location);
        });
      });
  });

Output:

{ key: 'c3', value: '3' }
{ key: 'a5', value: '5' }

License

MIT