Comparing version 0.0.2 to 0.0.3
@@ -135,3 +135,3 @@ /** | ||
}, | ||
remove = function (val, i, words, sub_trie, cb) | ||
@@ -147,9 +147,16 @@ { | ||
{ | ||
index = st.lastIndexOf(val); | ||
if (index >= 0) | ||
if (val === undefined) | ||
{ | ||
st.splice(index, 1); | ||
st = []; | ||
} | ||
else | ||
{ | ||
index = st.lastIndexOf(val); | ||
if (index >= 0) | ||
{ | ||
st.splice(index, 1); | ||
} | ||
} | ||
if (st.length === 0) | ||
@@ -278,3 +285,3 @@ { | ||
@param {String} topic The topic to match against. | ||
@param {Any} val The value to return if the topic is matched. | ||
@param {Any} val The value to return if the topic is matched. `undefined` is not supported. | ||
@param {Function} cb Called when the matcher has been added. | ||
@@ -291,3 +298,3 @@ */ | ||
@param {String} topic The topic that's being matched against. | ||
@param {Any} val The value that's being matched. | ||
@param {Any} [val] The value that's being matched. If you don't specify `val` then all matchers for `topic` are removed. | ||
@param {Function} cb Called when the matcher has been removed. | ||
@@ -297,3 +304,10 @@ */ | ||
{ | ||
remove(val, 0, topic.split(separator), trie, cb); | ||
if (arguments.length === 2) | ||
{ | ||
remove(undefined, 0, topic.split(separator), trie, val); | ||
} | ||
else | ||
{ | ||
remove(val, 0, topic.split(separator), trie, cb); | ||
} | ||
}; | ||
@@ -335,2 +349,9 @@ | ||
/** | ||
Reset the qlobber. | ||
Removes all topic matchers from the qlobber. | ||
@param {Function} cb Called when the qlobber has been reset. | ||
*/ | ||
QlobberObject.clear = function (cb) | ||
@@ -337,0 +358,0 @@ { |
{ | ||
"name": "qlobber", | ||
"description": "Node.js globbing for amqp-like topics", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/davedoesdev/qlobber", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -94,2 +94,3 @@ # qlobber [![Build Status](https://travis-ci.org/davedoesdev/qlobber.png)](https://travis-ci.org/davedoesdev/qlobber) | ||
- <a name="toc_qlobberobjectmatchtopic-cb"></a>[QlobberObject.match](#qlobberobjectmatchtopic-cb) | ||
- <a name="toc_qlobberobjectclearcb"></a>[QlobberObject.clear](#qlobberobjectclearcb) | ||
@@ -126,3 +127,3 @@ # Qlobber([options]) | ||
- `{String} topic` The topic to match against. | ||
- `{Any} val` The value to return if the topic is matched. | ||
- `{Any} val` The value to return if the topic is matched. `undefined` is not supported. | ||
- `{Function} cb` Called when the matcher has been added. | ||
@@ -132,3 +133,3 @@ | ||
# QlobberObject.remove(topic, val, cb) | ||
# QlobberObject.remove(topic, [val], cb) | ||
@@ -140,3 +141,3 @@ > Remove a topic matcher from the qlobber. | ||
- `{String} topic` The topic that's being matched against. | ||
- `{Any} val` The value that's being matched. | ||
- `{Any} [val]` The value that's being matched. If you don't specify `val` then all matchers for `topic` are removed. | ||
- `{Function} cb` Called when the matcher has been removed. | ||
@@ -161,2 +162,14 @@ | ||
# QlobberObject.clear(cb) | ||
> Reset the qlobber. | ||
Removes all topic matchers from the qlobber. | ||
**Parameters:** | ||
- `{Function} cb` Called when the qlobber has been reset. | ||
<sub>Go: [TOC](#tableofcontents) | [QlobberObject](#toc_qlobberobject)</sub> | ||
_—generated by [apidox](https://github.com/codeactual/apidox)—_ |
@@ -77,2 +77,20 @@ /*globals global */ | ||
global.rabbitmq_expected_results_after_remove_all = [ | ||
["a.b.c", ["t2", "t6", "t10", "t12", "t18", "t22", | ||
"t23", "t24", "t26"]], | ||
["a.b", ["t3", "t6", "t7", "t8", "t9", "t12", "t15", | ||
"t22", "t23", "t24", "t26"]], | ||
["a.b.b", ["t3", "t6", "t7", "t12", "t14", "t18", "t22", | ||
"t23", "t24", "t26"]], | ||
["", ["t6", "t17", "t24"]], | ||
["b.c.c", ["t6", "t18", "t22", "t23", "t24", "t26"]], | ||
["a.a.a.a.a", ["t6", "t12", "t22", "t23", "t24"]], | ||
["vodka.gin", ["t6", "t8", "t22", "t23", "t24"]], | ||
["vodka.martini", ["t6", "t8", "t22", "t23", "t24"]], | ||
["b.b.c", ["t6", "t10", "t13", "t18", "t22", "t23", | ||
"t24", "t26"]], | ||
["nothing.here.at.all", ["t6", "t22", "t23", "t24"]], | ||
["oneword", ["t6", "t22", "t23", "t24", "t25"]] | ||
]; | ||
global.rabbitmq_expected_results_after_clear = [ | ||
@@ -79,0 +97,0 @@ ["a.b.c", []], |
@@ -138,2 +138,25 @@ /*globals rabbitmq_test_bindings : false, | ||
it('should support removing all values for a topic', function (done) | ||
{ | ||
add_bindings(rabbitmq_test_bindings, false, null, function () | ||
{ | ||
async.each(rabbitmq_bindings_to_remove, function (i, cb) | ||
{ | ||
matcher.remove(rabbitmq_test_bindings[i-1][0], cb); | ||
}, function () | ||
{ | ||
expect(matcher.get_trie()).to.eql({"a":{"b":{"b":{"c":{".":["t4"]},".":["t14"]},".":["t15"]},"*":{"c":{".":["t2"]},".":["t9"]},"#":{"b":{".":["t3"]},"#":{".":["t12"]}}},"#":{"#":{".":["t6"],"#":{".":["t24"]}},"b":{".":["t7"],"#":{".":["t26"]}},"*":{"#":{".":["t22"]}}},"*":{"*":{".":["t8"],"*":{".":["t18"]}},"b":{"c":{".":["t10"]}},"#":{"#":{".":["t23"]}},".":["t25"]},"b":{"b":{"c":{".":["t13"]}},"c":{".":["t16"]}},"":{".":["t17"]}}); | ||
async.each(rabbitmq_expected_results_after_remove_all, function (test, cb) | ||
{ | ||
matcher.match(test[0], function (err, vals) | ||
{ | ||
expect(vals, test[0]).to.eql(test[1].sort()); | ||
cb(); | ||
}); | ||
}, done); | ||
}); | ||
}); | ||
}); | ||
it('should support functions as values', function (done) | ||
@@ -140,0 +163,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30960
642
171