validator
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -208,1 +208,15 @@ var net = require('net'); | ||
}; | ||
Validator.prototype.in = function(options) { | ||
//Syntactic sugar for string-in-string | ||
if (options && typeof options.indexOf === 'function') { | ||
if (! ~options.indexOf(this.str)) { | ||
return this.error(this.msg || 'Unexpected value'); | ||
} | ||
return this; | ||
} | ||
else { | ||
return this.error(this.msg || 'Invalid in() argument'); | ||
} | ||
}; |
{ "name" : "validator", | ||
"description" : "Data validation, filtering and sanitization for node.js", | ||
"version" : "0.2.3", | ||
"version" : "0.2.4", | ||
"homepage" : "http://github.com/chriso/node-validator", | ||
@@ -5,0 +5,0 @@ "keywords" : ["validator", "validation", "assert", "params", "sanitization", "xss", "entities", "sanitize", "sanitisation", "input"], |
@@ -75,2 +75,3 @@ **node-validator is a library of string validation, filtering and sanitization methods.** | ||
len(min, max) //max is optional | ||
in(options) //Accepts an array or string | ||
@@ -77,0 +78,0 @@ ## List of sanitization / filter methods |
@@ -393,5 +393,34 @@ var node_validator = require('../lib'), | ||
}, | ||
'test #in(options)': function () { | ||
assert.ok(Validator.check('foo').in('foobar')); | ||
assert.ok(Validator.check('foo').in('I love football')); | ||
assert.ok(Validator.check('foo').in(['foo', 'bar', 'baz'])); | ||
assert.throws(function() { | ||
Validator.check('foo').in(['bar', 'baz']); | ||
}, /unexpected/i | ||
); | ||
assert.throws(function() { | ||
Validator.check('foo').in('bar, baz'); | ||
}, /unexpected/i | ||
); | ||
assert.throws(function() { | ||
Validator.check('foo').in(1234567); | ||
}, /invalid/i | ||
); | ||
assert.throws(function() { | ||
Validator.check('foo').in({foo:"foo",bar:"bar"}); | ||
}, /invalid/i | ||
); | ||
} | ||
} | ||
Sorry, the diff of this file is not supported yet
96242
1990
168