iotcat
d328913389
|
5 years ago | |
---|---|---|
.. | ||
bench | 5 years ago | |
coverage | 5 years ago | |
lib | 5 years ago | |
test | 5 years ago | |
.npmignore | 5 years ago | |
.travis.yml | 5 years ago | |
Gruntfile.js | 5 years ago | |
LICENCE | 5 years ago | |
README.md | 5 years ago | |
index.js | 5 years ago | |
package.json | 5 years ago |
README.md
qlobber
Node.js globbing for amqp-like topics.
Example:
var Qlobber = require('qlobber').Qlobber;
var matcher = new Qlobber();
matcher.add('foo.*', 'it matched!');
assert.deepEqual(matcher.match('foo.bar'), ['it matched!']);
The API is described here.
qlobber is implemented using a trie, as described in the RabbitMQ blog posts here and here.
Installation
npm install qlobber
Another Example
A more advanced example using topics from the RabbitMQ topic tutorial:
var matcher = new Qlobber();
matcher.add('*.orange.*', 'Q1');
matcher.add('*.*.rabbit', 'Q2');
matcher.add('lazy.#', 'Q2');
assert.deepEqual(['quick.orange.rabbit',
'lazy.orange.elephant',
'quick.orange.fox',
'lazy.brown.fox',
'lazy.pink.rabbit',
'quick.brown.fox',
'orange',
'quick.orange.male.rabbit',
'lazy.orange.male.rabbit'].map(function (topic)
{
return matcher.match(topic).sort();
}),
[['Q1', 'Q2'],
['Q1', 'Q2'],
['Q1'],
['Q2'],
['Q2', 'Q2'],
[],
[],
[],
['Q2']]);
Licence
Tests
qlobber passes the RabbitMQ topic tests (I converted them from Erlang to Javascript).
To run the tests:
grunt test
Lint
grunt lint
Code Coverage
grunt coverage
Instanbul results are available here.
Coveralls page is here.
Benchmarks
grunt bench
qlobber is also benchmarked in ascoltatori.
API
Source: lib/qlobber.js
- Qlobber
- Qlobber.prototype.add
- Qlobber.prototype.remove
- Qlobber.prototype.match
- Qlobber.prototype.clear
- QlobberDedup
- QlobberDedup.prototype.match
Qlobber([options])
Creates a new qlobber.
Parameters:
{Object} [options]
Configures the qlobber. Use the following properties:-
{String} separator
The character to use for separating words in topics. Defaults to '.'. MQTT uses '/' as the separator, for example. -
{String} wildcard_one
The character to use for matching exactly one word in a topic. Defaults to '*'. MQTT uses '+', for example. -
{String} wildcard_some
The character to use for matching zero or more words in a topic. Defaults to '#'. MQTT uses '#' too.
-
Go: TOC
Qlobber.prototype.add(topic, val)
Add a topic matcher to the qlobber.
Note you can match more than one value against a topic by calling add
multiple times with the same topic and different values.
Parameters:
{String} topic
The topic to match against.{Any} val
The value to return if the topic is matched.undefined
is not supported.
Return:
{Qlobber}
The qlobber (for chaining).
Go: TOC | Qlobber.prototype
Qlobber.prototype.remove(topic, [val])
Remove a topic matcher from the qlobber.
Parameters:
{String} topic
The topic that's being matched against.{Any} [val]
The value that's being matched. If you don't specifyval
then all matchers fortopic
are removed.
Return:
{Qlobber}
The qlobber (for chaining).
Go: TOC | Qlobber.prototype
Qlobber.prototype.match(topic)
Match a topic.
Parameters:
{String} topic
The topic to match against.
Return:
{Array}
List of values that matched the topic. This may contain duplicates.
Go: TOC | Qlobber.prototype
Qlobber.prototype.clear()
Reset the qlobber.
Removes all topic matchers from the qlobber.
Return:
{Qlobber}
The qlobber (for chaining).
Go: TOC | Qlobber.prototype
QlobberDedup([options])
Creates a new de-duplicating qlobber.
Inherits from Qlobber.
Parameters:
{Object} [options]
Same options as Qlobber.
Go: TOC
QlobberDedup.prototype.match(topic)
Match a topic.
Parameters:
{String} topic
The topic to match against.
Return:
{Set}
ES6 Set of values that matched the topic.
Go: TOC | QlobberDedup.prototype
—generated by apidox—