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

object-conduit

v0.0.1

Published

Compose functions that take and return objects by continuously merging

Readme

object-conduit

Compose functions that take and return objects by continuously merging

Usage

var conduit = require('object-conduit')

The following example uses flyd streams. Say we have a silly app where a user clicks a button, and we want to keep a simple counter, plus a fibonacci counter, for every click they make.

We can define a couple functions, count and fib, like so:

function count (inp) {
  return {
    sum: flyd.scan((sum) => sum + 1, 0, inp.click)
  }
}
function fib (inp) {
  // Keep a stream of fib pairs
  const fibPairs = flyd.scan(([x, y]) => [y, x + y], [0, 1], inp.click)
  return {
    fib: flyd.scan((_, [x, y]) => x, 0, fibPairs)
  }
}

Each function takes an input object of streams and returns an output object of streams. The output object gets merged back with the input object after it's returned, so you don't lose any input streams. For example, the result of fib will get merged back with its input, so the result object has both sum and fib in it.

You can access any key in the input object and it will be a flyd stream. If it hasn't been previously defined in another function, then it will still be a stream. For example, we could access inp.xyz to get a flyd stream in either function (although it wouldn't be useful as it's not used anywhere).

We chain together streams, one after the other, using, the conduit function:

var input = {click: flyd.stream()}
var out = conduit(input, [count, fib])

That gives us a final object with all the properties we defined in each function: .sum, and .count, which both read from the stream in .click.

To use this object of streams (for example, in a view), you can push to some streams in the object to get corresponding values out of other streams.

out.click(true)
out.click(true)
out.click(true)
out.click(true)
out.click(true)
out.click(true)
t.strictEqual(out.sum(), 6)
t.strictEqual(out.fib(), 8) // 0, 1, 1, 3, 5, 8

Install

With npm installed, run

$ npm install object-conduit

See Also

License

MIT