New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bloomrun

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bloomrun

JS object pattern matching, powered by bloom filters

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3K
increased by28.81%
Maintainers
2
Weekly downloads
 
Created
Source

bloomrun

travis git npm

A js pattern matcher based on bloom filters, inspired by patrun. But different: 10x faster, and with results returned in insertion order.

Install

To install bloomrun, simply use npm:

npm install bloomrun --save

Example

The example below can be found here and ran using node example.js. It demonstrates how to use bloomrun for pattern matching with or without a payload.

'use strict'

var bloomrun = require('bloomrun')()

bloomrun.add({say: 'hello', msg: 'Hello World!'})
bloomrun.add({say: 'goodbye'}, function () {
  console.log('Goodbye World!')
})

var hello = bloomrun.lookup({say: 'hello'})
console.log(hello.msg)

var goodbye = bloomrun.lookup({say: 'goodbye'})
goodbye()

API


bloomrun()

Creates a new instance of Bloomrun.


instance.add(pattern [,payload])

Adds a pattern to the Bloomrun instance. You can also provide an alternative payload to return instead of the pattern itself. This allows pattern based retrieval of objects. If no payload is provided the pattern itself will be returned.


instance.remove(pattern [,payload])

Removes a pattern from the Bloomrun instance. Filters are rebuilt after each removal which may mean the same pattern is matched by another filter. In cases where two patterns differ only by payload, the supplied payload can be used to determine the correct match. If no payload is supplied any matched pattern will be removed regardless of it's own payload.


instance.lookup(obj)

Looks up the first entry that matches the given obj. A match happens when all properties of the added pattern matches with the one in the passed obj. If a payload was provided it will be returned instead of the pattern.


instance.iterator(obj)

Returns an iterator, which is an object with a next method. next will return the next pattern that matches the object or null if there are no more.


instance.list(obj)

Returns all patterns that matches the object. If a payload was provided this will be returned instead of the pattern.

Acknowledgements

This library is heavily inspired by Richard Rodger's patrun and seneca. Also, It would not be possible without bloomfilter.

License

Copyright Matteo Collina 2015, Licensed under MIT.

FAQs

Package last updated on 16 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc