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

bacon.matchers

v0.4.2

Published

The best project ever.

Downloads

2,389

Readme

Matcher library for Bacon.js.

You can map a Property / EventStream to a boolean one like using .is()

// Returns a Property of Booleans
age.is().equalTo(65)
salary.is().greaterThan(1000)

You can also filter using .where()

// Returns a filtered stream
keyUps.map(".keyCode").where().equalTo(30)

And there's negation

age.is().not().greaterThan(18)

You can compare to either constant values or other Observables. Like

// Returns a Property of Booleans
var collision = playerPos.is().equalTo(monsterPos)

You can give field extractor strings to .where() and .is(), like this:

Bacon.fromArray([
	{ name: "2001: A Space Odyssey", tags: ["SciFi"] },
	{ name: "The Godfather", tags: ["Crime", "Drama"] },
]).where('.tags').containerOf("SciFi")

=> { name: "2001: A Space Odyssey", tags: ["SciFi"] }

Bacon.fromArray([
	{ name: "2001: A Space Odyssey", tags: ["SciFi"] },
	{ name: "The Godfather", tags: ["Crime", "Drama"] },
]).is('.tags.length').greaterThan(1)

=> false, true

Complete examples:

Bacon.fromArray([1,2,3]).is().equalTo(2)

=> false, true, false

Bacon.fromArray([1,2,3]).where().equalTo(2)

=> 2

Additions to Observable API

Observable.is() returns a Matchers object for mapping to booleans.

Observable.where() returns a Matchers object for filtering.

Matchers API

lessThan(x) applies < matcher

lessThanOrEqualTo(x) applies <= matcher

greaterThan(x) applies > matcher

greaterThanOrEqualTo applies >= matcher

inClosedRange(a, b) applies [a..b] range matcher

inOpenRange(a, b) applies (a..b) range matcher

equalTo(x) applies == matcher

truthy() applies "truthy" matcher

match(expr) applies regular expression matcher

not() returns a negated Matchers object

containerOf(x) and memberOf(x) support arrays, strings and object key-values. Examples:

stream = Bacon.once([6]).is().containerOf(6) // is true
stream = Bacon.once(6).is().memberOf([6]) // is true

Bacon.once('hello bacon').is().containerOf('bacon') // is true
Bacon.once('bacon').is().memberOf('hello bacon') // is true

Bacon.once({
  alien: 'morninglightmountain'
  human: 'dudleybose'
}).is().containerOf({ alien: 'morninglightmountain' }) // is true

Bacon.once({ alien: 'morninglightmountain' })
  .is().memberOf({
  alien: 'morninglightmountain'
  human: 'dudleybose'
}) // is true

some(fs...) applies multiple "clauses", and matches when any clause is true. Clauses are functions that map the observable to an observable of boolean values. For example:

Bacon.once({ power_pill: true,   ghosts: ["Inky", "Pinky"]})
  .is()
  .some(
    function(stream){ return stream.is(".power_pill").truthy(); },
    function(stream){ return stream.is(".ghosts").containerOf("Clyde"); }
  ) // is true

every(fs...) applies multiple "clauses", and matches when all clauses are true. For example:

Bacon.once({ power_pill: true,   ghosts: ["Inky", "Pinky"]})
  .is()
  .every(
    function(stream){ return stream.is(".power_pill").truthy(); },
    function(stream){ return stream.is(".ghosts").containerOf("Clyde"); }
  ) // is false

Browser support

IE 9 and above.

Download / Install

  • Download javascript file
  • NPM: registered as bacon.matchers
  • Bower: registered as bacon.matchers

Tests

Tests are located in the spec directory. You can run them by installing dependencies with npm install and then executing the run-tests script.