Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Set#ismember(str)

  • Loading branch information...
commit 501f3383df6d8798683f9eaacfa92d171d9c6aa3 1 parent 9a66d6a
@tj authored
Showing with 31 additions and 0 deletions.
  1. +15 −0 lib/objects/set.js
  2. +16 −0 test/set.test.js
View
15 lib/objects/set.js
@@ -78,6 +78,21 @@ Set.prototype.random = function(fn){
};
/**
+ * Check if `str` is a member and callback `fn(err, status)`.
+ *
+ * @param {String} str
+ * @param {Function} fn
+ * @return {Set} for chaining
+ * @api public
+ */
+
+Set.prototype.ismember =
+Set.prototype.has = function(str, fn){
+ this.client.sismember(this.key, str, fn);
+ return this;
+};
+
+/**
* Get the members in this set and callback`fn(err, members)`.
*
* @param {Function} fn
View
16 test/set.test.js
@@ -35,6 +35,22 @@ module.exports = {
});
},
+ '.ismember(str)': function(done){
+ var names = new Set('names');
+ names.add('tj');
+ names.add('aaron');
+ names.add('guillermo');
+ should.equal(true, names.ismember == names.has, 'ismember() has() alias is missing');
+ names.ismember('tj', function(err, yes){
+ yes.should.equal(1);
+ names.ismember('tobi', function(err, yes){
+ yes.should.equal(0);
+ names.client.end();
+ done();
+ });
+ });
+ },
+
'.pop()': function(done){
var names = new Set('names');
names.add('tj');
Please sign in to comment.
Something went wrong with that request. Please try again.