-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 35be4e8
Showing
10 changed files
with
895 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 0.8 | ||
- 0.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*jslint node: true */ | ||
"use strict"; | ||
|
||
module.exports = function (grunt) | ||
{ | ||
grunt.initConfig( | ||
{ | ||
jslint: { | ||
files: [ 'Gruntfile.js', 'index.js', 'test/*.js' ], | ||
directives: { | ||
white: true | ||
} | ||
}, | ||
|
||
cafemocha: { | ||
src: 'test/*.js' | ||
}, | ||
|
||
apidox: { | ||
input: 'lib/qlobber.js', | ||
output: 'README.md', | ||
fullSourceDescription: true | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-jslint'); | ||
grunt.loadNpmTasks('grunt-cafe-mocha'); | ||
grunt.loadNpmTasks('grunt-apidox'); | ||
|
||
grunt.registerTask('lint', 'jslint'); | ||
grunt.registerTask('test', 'cafemocha'); | ||
grunt.registerTask('docs', 'apidox'); | ||
grunt.registerTask('default', ['jslint', 'cafemocha']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2013 David Halls <https://github.com/davedoesdev/> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# qlobber | ||
|
||
Node.js globbing for amqp-like topics. | ||
|
||
Example: | ||
|
||
```javascript | ||
Qlobber = require('qlobber').Qlobber; | ||
matcher = new Qlobber(); | ||
matcher.add('foo.*', 'it matched!', function () | ||
{ | ||
matcher.match('foo.bar', function (err, vals) | ||
{ | ||
assert.deepEqual(vals, ['it matched!']); | ||
}); | ||
}); | ||
``` | ||
|
||
The API is described [here](#tableofcontents). | ||
|
||
qlobber is implemented using a trie, as described in the RabbitMQ blog posts [here](http://www.rabbitmq.com/blog/2010/09/14/very-fast-and-scalable-topic-routing-part-1/) and [here](http://www.rabbitmq.com/blog/2011/03/28/very-fast-and-scalable-topic-routing-part-2/). | ||
|
||
A more advanced example using topics from the [RabbitMQ topic tutorial](http://www.rabbitmq.com/tutorials/tutorial-five-python.html): | ||
|
||
```javascript | ||
async.parallel( | ||
[matcher.add.bind(matcher, '*.orange.*', 'Q1'), | ||
matcher.add.bind(matcher, '*.*.rabbit', 'Q2'), | ||
matcher.add.bind(matcher, 'lazy.#', 'Q2')], | ||
async.mapSeries.bind(async, | ||
['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'], | ||
matcher.match, | ||
function (err, vals) | ||
{ | ||
assert.deepEqual(vals, | ||
[['Q1', 'Q2'], | ||
['Q1', 'Q2'], | ||
['Q1'], | ||
['Q2'], | ||
['Q2'], | ||
[], | ||
[], | ||
[], | ||
['Q2']]); | ||
})); | ||
``` | ||
|
||
## Licence | ||
|
||
[MIT](LICENCE) | ||
|
||
## Tests | ||
|
||
qlobber passes the [RabbitMQ topic tests](https://github.com/rabbitmq/rabbitmq-server/blob/master/src/rabbit_tests.erl) (I converted them from Erlang to Javascript). | ||
|
||
To run the tests: | ||
|
||
```javascript | ||
grunt test | ||
``` | ||
|
||
## Lint | ||
|
||
```javascript | ||
grunt lint | ||
``` | ||
|
||
# API | ||
|
||
_Source: [lib/qlobber.js](lib/qlobber.js)_ | ||
|
||
<a name="tableofcontents"></a> | ||
|
||
- <a name="toc_qlobberoptions"></a>[Qlobber](#qlobberoptions) | ||
- <a name="toc_qlobberobjectaddtopic-val-cb"></a><a name="toc_qlobberobject"></a>[QlobberObject.add](#qlobberobjectaddtopic-val-cb) | ||
- <a name="toc_qlobberobjectremovetopic-val-cb"></a>[QlobberObject.remove](#qlobberobjectremovetopic-val-cb) | ||
- <a name="toc_qlobberobjectmatchtopic-cb"></a>[QlobberObject.match](#qlobberobjectmatchtopic-cb) | ||
|
||
# Qlobber([options]) | ||
|
||
> Creates a new qlobber. | ||
**Parameters:** | ||
|
||
- `{Object} [options]` Configures the globber. 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. | ||
|
||
- `{String | false} compare` The function to use for sorting matches in order to remove duplicates. Defaults to lexicographical string compare. Specify `false` to turn off duplicate removal. If you store values other than strings in qlobber, pass in your own compare function. | ||
|
||
<sub>Go: [TOC](#tableofcontents)</sub> | ||
|
||
<a name="qlobberobject"></a> | ||
|
||
# QlobberObject.add(topic, val, cb) | ||
|
||
> 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. | ||
- `{Function} cb` Called when the matcher has been added. | ||
|
||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
|
||
# QlobberObject.remove(topic, val, cb) | ||
|
||
> 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. | ||
- `{Function} cb` Called when the matcher has been removed. | ||
|
||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
|
||
# QlobberObject.match(topic, cb) | ||
|
||
> Match a topic. | ||
**Parameters:** | ||
|
||
- `{String} topic` The topic to match against. | ||
- `{Function} cb` Called with two arguments when the match has completed: | ||
|
||
|
||
- `{Any} err` `null` or an error, if one occurred. | ||
- `{Array} vals` List of values that matched the topic. `vals` will be sorted and have duplicates removed unless you configured [Qlobber](#qlobberoptions) otherwise. | ||
|
||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
|
||
_—generated by [apidox](https://github.com/codeactual/apidox)—_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*jslint node: true*/ | ||
"use strict"; | ||
module.exports = require('./lib/qlobber'); |
Oops, something went wrong.