Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Throw is a value passed to numItems is not an object or an array.

  • Loading branch information...
commit aeb0b31342cfb7b8444e5cebd17c4d419009ebf1 1 parent 47bd2a5
@Kami Kami authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/validators.js
View
11 lib/validators.js
@@ -1,5 +1,7 @@
var check = require('validator').check;
+var utils = require('./util');
+
exports.isPort = function(value, baton) {
value = parseInt(value, 10);
@@ -43,14 +45,17 @@ exports.isHostname = function(value) {
* @param {Number} max Maximum number of elements.
*/
exports.numItems = function(value, min, max) {
- var len;
+ var len, type = utils.typeOf(value);
- if (value instanceof Array) {
+ if (type === 'array') {
len = value.length;
}
- else {
+ else if (type === 'object') {
len = Object.keys(value).length;
}
+ else {
+ throw new Error('value must either be a array or an object');
+ }
if (len < min || len > max) {
throw new Error('Object needs to have between ' + min + ' and ' + max + ' items');
Please sign in to comment.
Something went wrong with that request. Please try again.