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 🙏

© 2026 – Pkg Stats / Ryan Hefner

join_streams

v0.1.2

Published

sql-like join of object streams based on keys. Each stream must be sorted.

Readme

Join Streams

Joins the fields from two object streams, to create a single object stream in the output. Unlike other stream-joining modules available on NPM, this module combines objects from the first stream with objects from the second stream that have certain fields (designated as keys) whose values match. In other words, this is an implementation of an SQL JOIN for Node JS streams, including support for INNER, LEFT and OUTER joins.

Installation

$ npm install --save join_streams

Example

const comparer = require('flat-object-compare');
const join = require('join_streams')
const streamify = require('stream-array')

var comp = comparer.objectComparison(['country',]);

var stream1 = [
    { country: 'Mexico', capital: 'Mexico City' },
    { coutnry: 'Indonesia', capital: 'Jakarta' },
    { country: 'Nigeria', capital: 'Abuja'},
    { country: 'Turkey', capital: 'Ankara'},
]

var stream2 = [
    { country: 'Mexico', gdp: 1283 },
    { coutnry: 'Indonesia', gdp: 2686 },
    { country: 'Nigeria', gdp: 574},
    { country: 'Turkey', gdp: 1508},    
]

var result =[];

join(streamify(stream1.sort(comp)), streamify(stream2.sort(comp)), { comp: comp, joinType: 'inner' })
				.on('data', function (data) {
					result.push(data)
				}).on('end', function () {
                    console.log(JSON.stringify(result))
                })
/*
For inner join, only the countries that appear in both streams (i.e. comparison function returns a zero) will appear in output.
[{"coutnry":"Indonesia","capital":"Jakarta","gdp":889},{"country":"Mexico","capital":"Mexico City","gdp":1283},{"country":"Nigeria","capital":"Abuja","gdp":574},{"country":"Turkey","capital":"Ankara","gdp":751}]
*/

API

join(streamA, streamB, options)

streamA, streamB - streams to join.

options - an object with the following fields:

  • comp: a comparison function, which takes two parameters (objects of streamA and streamB respectively) and returns -1, 0, or 1 when objectA's key comes before, is equal to, or comes after objectB's key (respectively). This field is mandatory. See flat-object-compare npm module for a quick way to generate a comparison function from just the field names.
  • joinType:
    • 'inner' - performs inner join. Output stream will contain only objects where the key matched between streamA and streamB.
    • 'left' - non-matched objects from streamA are preserved; non-matched objects from streamB are discarded
    • 'outer' - non-matched objects from both streamA and streamB are preserved in the output.
  • fuse: an optional field. This controls how the output object will be created from the two input objects. Overriding the default is discouraged except when very specific behavior is desired with regards to empty values (NaN,undefined). To override default, supply a function that takes in two object arguments and return an object. join_streams calls the fuse function on any pair of matching objects, and sends to the output the object returned by the fuse function.

Notes

  1. with 'left' or 'outer' join, non-matched objects are passed to the output stream. These objects will still contain all the fields of both A and B; the missing fields will have the value null. To change this behavior, provide an implementation for the fuse function.
  2. the default join type is 'inner'.
  3. join_streams assumes each input stream was sorted by the same comparison function that is used to join. An unsorted stream will not raise any exception, but the result may be incomplete.
  4. join_streams fully supports repeating keys and outputs all the corresponding matches.
  5. join_streams is very lean on memory. Its memory consumption does not rise with the number of processed elements. Therefore it is suitable for prototyping big-data pipelines.