chriso/node-validator — pull request #158 by maxnachlinger (2013-03-01 04:54:40+00:00)
Title: Typed array validations

Not sure if this is functionality you're keen on adding to your library, but I had a recent need to validate that each element in a given array was of a certain type. So I created a simple array is-of-type validator, which (aside from the standard str arg) takes a validation method to run against each element of the array. The method looks like this:
```javascript
isTypedArray: function(str, typeFx) {
if(!validators.isArray(str) || !str.length) {
return false;
}
for (var i = 0; i < str.length; i++) {
if(!typeFx(str[i])) {
return false;
}
}
return true;
},
```
Which of course made checking for an array of ints as easy as:
```javascript
isIntArray: function(str) {
return validators.isTypedArray(str, validators.isInt);
},
```
My only concern is that the above might somehow break the nice single-responsibility of each of the existing validation methods. At any rate, if this is useful I imagine that additional array-of-type validations would be just a easy.