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

stream-joins

v0.1.5

Published

Join operations for ordered object-mode streams (e.g. timeseries data). Various types of join operations that join two timeseries streams into a single stream.

Downloads

25

Readme

stream-joins

NPM

Join operations for ordered objectMode streams (e.g. timeseries data). Various types of join operations that join two timeseries streams into a single stream.

// timestream-gen generates timeseries data ordered by a sequence key "_t"
var gen = require("timestream-gen").gen
var concat = require("concat-stream")

var joins = require("stream-joins")

// Perform a UNION
joins.union("_t",
  gen({start: 0, until: 5000, interval: 1000, key: "L"}),
  gen({start: 500, until: 5500, interval: 750, key: "R"})
).pipe(concat(console.log))

/*
[ { L: 0, _t: 0 },
  { R: 0, _t: 500 },
  { L: 1, _t: 1000 },
  { R: 1, _t: 1250 },
  { R: 2, _t: 2000, L: 2 },
  { R: 3, _t: 2750 },
  { L: 3, _t: 3000 },
  { R: 4, _t: 3500 },
  { L: 4, _t: 4000 },
  { R: 5, _t: 4250 },
  { R: 6, _t: 5000, L: 5 } ]
 */

// Perform a LEFT JOIN
joins.join("_t",
  gen({start: 0, until: 5000, interval: 1000, key: "L"}),
  gen({start: 500, until: 5500, interval: 750, key: "R"})
).pipe(concat(console.log))

/*
[ { L: 0, _t: 0 },
  { L: 1, _t: 1000 },
  { R: 2, _t: 2000, L: 2 },
  { L: 3, _t: 3000 },
  { L: 4, _t: 4000 },
  { R: 6, _t: 5000, L: 5 } ]
 */

// Perform a COMPLEMENT
joins.complement("_t",
  gen({start: 0, until: 5000, interval: 1000, key: "L"}),
  gen({start: 500, until: 5500, interval: 750, key: "R"})
).pipe(concat(console.log))

/*
[ { R: 0, _t: 500 },
  { R: 1, _t: 1250 },
  { R: 3, _t: 2750 },
  { R: 4, _t: 3500 },
  { R: 5, _t: 4250 } ]
 */

// Perform a SYMMETRIC DIFFERENCE
joins.diff("_t",
  gen({start: 0, until: 5000, interval: 1000, key: "L"}),
  gen({start: 500, until: 5500, interval: 750, key: "R"})
).pipe(concat(console.log))

/*
[ { L: 0, _t: 0 },
  { R: 0, _t: 500 },
  { L: 1, _t: 1000 },
  { R: 1, _t: 1250 },
  { R: 3, _t: 2750 },
  { L: 3, _t: 3000 },
  { R: 4, _t: 3500 },
  { L: 4, _t: 4000 },
  { R: 5, _t: 4250 } ]
 */

// Perform an INTERSECT
joins.intersect("_t",
  gen({start: 0, until: 5000, interval: 1000, key: "L"}),
  gen({start: 500, until: 5500, interval: 750, key: "R"})
).pipe(concat(console.log))

/*
[ { R: 2, _t: 2000, L: 2 },
  { R: 6, _t: 5000, L: 5 } ]
 */

API

Join operations combine two streams based on the specified sequence key. All operations are considered left side operations, that is when combining records, they will use the left values where matching records have keys that overlap.

All operations accept the sequence key as the first argument. The streams MUST be already ordered by this sequence key for the joins to work correctly.

NOTE: In real-world scenarios with timestamp sequences, you'll typically want to do an aggregation operation before joining to make sure the timestamps match. These joins all look for exact matches.

  • union
  • join
  • intersect
  • complement
  • diff
  • where

.union(key, left, right)

Perform a left union operation. Take all records from both sets. Combine overlapping records.

.join(key, left, right)

Perform a left join operation. Take all records from the left set, combined with any values from matching records in the right set.

.intersect(key, left, right)

Perform a left intersection. Take only records where both sets have matching timestamps.

.complement(key, left, right)

Perform a complement. Of the two sets take only records that complement the left set, that is records on the right only that have no matching left record.

.diff(key, left, right)

Perform a symmetric difference. Keep only records where neither set overlaps the other.

.where(key, filter, left, right)

Performs something like a left join with a filter function. If your filter returns true it will keep the left record, otherwise it will skip it. Filter function is filter(leftRecord, rightRecord) where rightRecord could be null. The record can be mutated in your filter function.

Unlike the join above it does not automatically join the records, though because you can mutate records, you can do it yourself with something like xtend.

E.g.

function odds(left, right) {
  if (left.L % 2 != 0) {
    // Need to manually mutate the left record to do the join.
    if (right) left.R = right.R
    return true
  }
}

where(key, odds, left, right)
  .pipe(concat(collect))

LICENSE

MIT