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

eventuate-filter

v4.3.0

Published

Create filtered eventuate, acting as subset of broader eventuate

Downloads

18

Readme

eventuate-filter

NPM version Build Status Coverage Status Sauce Test Status

Create an eventuate that re-produces a subset of events from another eventuate.

This tiny module is also part of the larger aggregate module: eventuate

This module may also be used stand-alone, with eventuate-core.

example

var eventuate = require('eventuate-core'),
    filter    = require('eventuate-filter')

var logMessage = eventuate()
var errorMessage = filter(logMessage, function (log) {
    return log.level === 'error'
})

errorMessage(function (log) {
    console.error(log.message)
})

logMessage.produce({ level: 'info', message: 'something happened' })
logMessage.produce({ level: 'error', message: 'something bad happened' })
logMessage.produce({ level: 'info', message: 'something else happened' })

// output:
// something bad happened

api

var eventuate = require('eventuate-core')
var filter    = require('eventuate-filter')

var upstreamEventuate = eventuate()

The API of the filteredEventuate is mostly identical to the eventuate it is filtering.

var filteredEventuate = filter(upstreamEventuate, options, filterFunc)

Returns a new eventuate, filteredEventuate, which re-produces events from a non-basic eventuate, upstreamEventuate, for which filterFunc returns or resolves to true.

Valid options are:

  • requireConsumption (default: false) - throw an error if a produced event is not consumed
  • destroyResidual (default: true) - call the destroy function when the last consumer is removed via removeConsumer or removeAllConsumers (after at least one consumer was added)
  • lazy (default: true) - wait until a consumer is added before consuming from upstreamEventuate. If set to false, will begin consuming/filtering/producing immediately, even with no consumers added. This is useful when used in conjunction with requireConsumption, for example.
  • order (default: false) - insure the order of items output match the order of input, even with an async filter. Be careful using this option, as it will cause buffering.

The filterFunc function should accept at least one argument, data, but may optionally accept a 2nd argument of a callback; eventuate-filter will determine whether a callback is accepted based on the argument length of the filterFunc function.

If a callback is NOT accepted, then filterFunc should return either a boolean or a Promise. If a Promise is returned, it should resolve to a boolean. If a callback is accepted, the return value of filterFunc is ignored, and the error-first style callback (function (err, bool) {}) must be called with either a truthy error or a falsey error and a boolean.

Upon receiving a truthy boolean from either a return value, Promise, or callback, the filteredEventuate will produce the data in question.

If either the callback is supplied an error, or the Promise is rejected, then the filteredEventuate will produce an Error object.

If the callback or Promise are resolved/rejected after the filteredEventuate has been destroyed, the value will not be produced.

filteredEventuate.destroy()

When destroyed, the filteredEventuate will stop consuming from the upstreamEventuate. The filteredEventuate is automatically destroyed unless the destroyResidual option was given as false during creation of the filteredEventuate.

filteredEventuate.upstreamConsumer

The function added as a consumer to the upstreamEventuate.

install

With npm do:

npm install --save eventuate-core

testing

npm test

Or to run tests in phantom: npm run phantom

coverage

npm run view-cover

This will output a textual coverage report.

npm run open-cover

This will open an HTML coverage report in the default browser.