validateParams.js
function(value, options){
        // implicitly pass undefined
        var valType = typeof value;
        if(valType === 'undefined') return undefined;
        
        // make sure the default options object exists
        if(typeof this.options !== 'object') this.options = {};
        
        // build up a base config from the pre-defined defaults
        var config = {};
        config.types = validate.isArray(this.options.types) ? this.options.types : [];
        config.inverseMatch = this.options.inverseMatch ? true : false;
        config.message = validateParams.extractValidatorMessage(this, options);
        
        // interpret the passed value
        if(typeof options === 'string'){
            config.types.push(options);
        }else if(validate.isArray(options)){
            config.types = config.types.concat(options);
        }else if(validate.isObject(options)){
            if(validate.isArray(options.types)){
                config.types = config.types.concat(options.types);
            }
            if(options.inverseMatch) config.inverseMatch = true;
            if(validate.isString(options.message)) config.message = options.message;
        }else{
            throw new Error('invalid options passed - must be a string, an array of strings, or a plain object');
        }
        
        // validate the passed types
        var typeList = [];
        config.types.forEach(function(t){
            if(validateParams.isTypeofString(t) && t !== 'undefined'){
                typeList.push(t);
            }else{
                validateParams._warn('ignoring invalid type: ' + String(t));
            }
        });
        if(typeList.length === 0){
            throw new Error('no valid types specified');
        }
        
        // do the actual validation
        var errors = [];
        if(config.inverseMatch){
            // do a reverse match
            typeList.forEach(function(t){
                if(valType === t){
                    errors.push("can't have type '" + t + "'");
                }
            });
        }else{
            // do a regular forward match
            var matched = false;
            typeList.forEach(function(t){
                if(valType === t){
                    matched = true;
                }
            });
            if(!matched){
                errors.push("must have one of the following types: " + humanJoin(typeList) + "'");
            }
        }
        
        // return as appropriate
        if(errors.length > 0){
            return config.message ? config.message : errors;
        }
        return undefined;
    }
function(value, options){
        // implicitly pass undefined
        var valType = typeof value;
        if(valType === 'undefined') return undefined;
        
        // make sure the default options object exists
        if(typeof this.options !== 'object') this.options = {};
        
        // build up a base config from the pre-defined defaults
        var config = {};
        config.types = validate.isArray(this.options.types) ? this.options.types : [];
        config.inverseMatch = this.options.inverseMatch ? true : false;
        config.message = validateParams.extractValidatorMessage(this, options);
        
        // interpret the passed value
        if(typeof options === 'string'){
            config.types.push(options);
        }else if(validate.isArray(options)){
            config.types = config.types.concat(options);
        }else if(validate.isObject(options)){
            if(validate.isArray(options.types)){
                config.types = config.types.concat(options.types);
            }
            if(options.inverseMatch) config.inverseMatch = true;
            if(validate.isString(options.message)) config.message = options.message;
        }else{
            throw new Error('invalid options passed - must be a string, an array of strings, or a plain object');
        }
        
        // validate the passed types
        var typeList = [];
        config.types.forEach(function(t){
            if(validateParams.isTypeofString(t) && t !== 'undefined'){
                typeList.push(t);
            }else{
                validateParams._warn('ignoring invalid type: ' + String(t));
            }
        });
        if(typeList.length === 0){
            throw new Error('no valid types specified');
        }
        
        // do the actual validation
        var errors = [];
        if(config.inverseMatch){
            // do a reverse match
            typeList.forEach(function(t){
                if(valType === t){
                    errors.push("can't have type '" + t + "'");
                }
            });
        }else{
            // do a regular forward match
            var matched = false;
            typeList.forEach(function(t){
                if(valType === t){
                    matched = true;
                }
            });
            if(!matched){
                errors.push("must have one of the following types: " + humanJoin(typeList) + "'");
            }
        }
        
        // return as appropriate
        if(errors.length > 0){
            return config.message ? config.message : errors;
        }
        return undefined;
    }
function ( value , options ) { // implicitly pass undefined var valType = typeof value ; if ( valType === 'undefined' ) return undefined ; // make sure the default options object exists if ( typeof this . options !== 'object' ) this . options = { } ; // build up a base config from the pre-defined defaults var config = { } ; config . types = validate . isArray ( this . options . types ) ? this . options . types : [ ] ; config . inverseMatch = this . options . inverseMatch ? true : false ; config . message = validateParams . extractValidatorMessage ( this , options ) ; // interpret the passed value if ( typeof options === 'string' ) { config . types . push ( options ) ; } else if ( validate . isArray ( options ) ) { config . types = config . types . concat ( options ) ; } else if ( validate . isObject ( options ) ) { if ( validate . isArray ( options . types ) ) { config . types = config . types . concat ( options . types ) ; } if ( options . inverseMatch ) config . inverseMatch = true ; if ( validate . isString ( options . message ) ) config . message = options . message ; } else { throw new Error ( 'invalid options passed - must be a string, an array of strings, or a plain object' ) ; } // validate the passed types var typeList = [ ] ; config . types . forEach ( function ( t ) { if ( validateParams . isTypeofString ( t ) && t !== 'undefined' ) { typeList . push ( t ) ; } else { validateParams . _warn ( 'ignoring invalid type: ' + String ( t ) ) ; } } ) ; if ( typeList . length === 0 ) { throw new Error ( 'no valid types specified' ) ; } // do the actual validation var errors = [ ] ; if ( config . inverseMatch ) { // do a reverse match typeList . forEach ( function ( t ) { if ( valType === t ) { errors . push ( "can't have type '" + t + "'" ) ; } } ) ; } else { // do a regular forward match var matched = false ; typeList . forEach ( function ( t ) { if ( valType === t ) { matched = true ; } } ) ; if ( ! matched ) { errors . push ( "must have one of the following types: " + humanJoin ( typeList ) + "'" ) ; } } // return as appropriate if ( errors . length > 0 ) { return config . message ? config . message : errors ; } return undefined ; }
A validator for filtering values by the result of applying the `typeof`
operator to them.

This validator supports the following options in addition to the standard
`message` option:
* `types` - an array of one or more types as strings
* `inverseMatch` - a truthy value to invert the search, accepting all
types except those listed.

When used in a constraint, this validator supports the following values:
* A plain object specifying options.
* An array of strings - a shortcut for `{ types: THE_ARRAY }`, i.e. the
type must be one of the strings in the array.
* A string - a shortcut for `{ types: ['THE_STRING'] }`, i.e. the type
must be the given string.

@member
@type {Validator}
@see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof}
@example <caption>An optional first parameter that must be a callback if present</caption>
validateParams.assert(arguments, [{hasTypeof: 'function'}]);
@example <caption>A required first parameter that must be a string or a number</caption>
validateParams(arguments, [
{
defined: true,
hasTypeof: ['string', 'number']
}
]);
@example <caption>An optional first parameter that can be anything but a function</caption>
validateParams(arguments, [{
hasTypeof: {
types: ['function'],
inverseMatch: true
}
}]);
A validator for filtering values by the result of applying the typeof operator to them .