git ssb

0+

Kira / pull-routing



Branch:
Kira Oakley committed 1.0.1Latest: 1bc2d3e on 9/30/2020, 5:57:55 PM
📄.npmignore
📄README.md
📄index.js
📄package.json
📁test
README.md

pull-routing

A special pull-stream sink that multiplexes to several sinks based on router rules.

Usage

var Router = require('pull-routing')
const pull = require('pull-stream')

const router = Router()

router.addRoute(
  x => x % 2 === 0,
  pull.drain(x => console.log('EVEN', x))
)

router.addRoute(
  x => x % 2 === 1,
  pull.drain(x => console.log('ODD', x))
)

pull(
  pull.values([0,1,2,3]),
  router
)

outputs

EVEN 0
ODD 1
EVEN 2
ODD 3

API

const Router = require('pull-routing')

const router = Router()

Create a new router. Acts like a pull-stream sink.

router.addRoute(fn, sink)

Adds a route to the router. For data received by the router, if fn(data)
returns true, the data will go to sink (which can be a sink OR through stream).

Behaviour Notes

Install

With npm installed, run

$ npm install pull-routing

License

MIT

Built with git-ssb-web