Return default if undefined, otherwise validate Return a COPY of the validated parameter
326902
function(param, type, defaultParam) {
                    if(param == null && defaultParam != null)
                        return defaultParam;

                    switch(type) {

                        // Array of 1 item or more
                        case "a":
                            if(!Array.isArray(param) || !param.length) throw new Error("Expected an array of length 1 or greater");
                            return param.slice(0);

                        // Integer
                        case "int":
                            if(param !== Number(param)) throw new Error("A required parameter is missing or not a number");
                            if(param !== Math.round(param)) throw new Error("Parameter must be a whole number");
                            if(param === Infinity) throw new Error("Sent 'infinity' as a parameter");
                            return param;

                        // Natural number
                        case "n":
                            if(param === undefined) throw new Error("You must specify how many values you want");
                            if(param !== Number(param)) throw new Error("The number of values must be numeric");
                            if(param !== Math.round(param)) throw new Error("The number of values must be a whole number");
                            if(param < 1) throw new Error("The number of values must be a whole number of 1 or greater");
                            if(param === Infinity) throw new Error("The number of values cannot be infinite ;-)");
                            return param;

                        // Valid probability
                        case "p":
                            if(Number(param) !== param) throw new Error("Probability value is missing or not a number");
                            if(param > 1) throw new Error("Probability values cannot be greater than 1");
                            if(param < 0) throw new Error("Probability values cannot be less than 0");
                            return param;

                        // Positive numbers
                        case "pos":
                            if(Number(param) !== param) throw new Error("A required parameter is missing or not a number");
                            if(param <= 0) throw new Error("Parameter must be greater than 0");
                            if(param === Infinity) throw new Error("Sent 'infinity' as a parameter");
                            return param;

                        // Look for numbers (reals)
                        case "r":
                            if(Number(param) !== param) throw new Error("A required parameter is missing or not a number");
                            if(param === Infinity) throw new Error("Sent 'infinity' as a parameter");
                            return param;

                        // Non negative real number
                        case "nn":
                            if(param !== Number(param)) throw new Error("A required parameter is missing or not a number");
                            if(param < 0) throw new Error("Parameter cannot be less than 0");
                            if(param === Infinity) throw new Error("Sent 'infinity' as a parameter");
                            return param;

                        // Non negative whole number (integer)
                        case "nni":
                            if(param !== Number(param)) throw new Error("A required parameter is missing or not a number");
                            if(param !== Math.round(param)) throw new Error("Parameter must be a whole number");
                            if(param < 0) throw new Error("Parameter cannot be less than zero");
                            if(param === Infinity) throw new Error("Sent 'infinity' as a parameter");
                            return param;

                        // Non-empty string
                        case "str":
                            if(param !== String(param)) throw new Error("A required parameter is missing or not a string");
                            if(param.length === 0) throw new Error("Parameter must be at least one character long");
                            return param;


                    }
                }
527980
function(scope, defaultValue) {
            var val = evaluator(tree, scope);
            if( typeof defaultValue === 'undefined') {
                return val;
            } else {
                return (val === undefined || val === null || val != val) ? defaultValue : val;
            }
        }
630402
function( params ){
      var defaults = { 
        field: 'data',
        event: 'data',
        triggerFnName: 'trigger',
        triggerEvent: false,
        immutableKeys: {} // key => true if immutable
      };
      params = $$.util.extend({}, defaults, params);

      return function removeDataImpl( names ){
        var p = params;
        var self = this;
        var selfIsArrayLike = self.length !== undefined;
        var all = selfIsArrayLike ? self : [self]; // put in array if not array-like
        var single = selfIsArrayLike ? self[0] : self;
        
        // .removeData('foo bar')
        if( $$.is.string(names) ){ // then get the list of keys, and delete them
          var keys = names.split(/\s+/);
          var l = keys.length;

          for( var i = 0; i < l; i++ ){ // delete each non-empty key
            var key = keys[i];
            if( $$.is.emptyString(key) ){ continue; }

            var valid = !p.immutableKeys[ key ]; // not valid if immutable
            if( valid ){
              for( var i_a = 0, l_a = all.length; i_a < l_a; i_a++ ){
                delete all[ i_a ]._private[ p.field ][ key ];
              }
            }
          }

          if( p.triggerEvent ){
            self[ p.triggerFnName ]( p.event );
          }

        // .removeData()
        } else if( names === undefined ){ // then delete all keys

          for( var i_a = 0, l_a = all.length; i_a < l_a; i_a++ ){
            var _privateFields = all[ i_a ]._private[ p.field ];
            
            for( var key in _privateFields ){
              var validKeyToDelete = !p.immutableKeys[ key ];

              if( validKeyToDelete ){
                delete _privateFields[ key ];
              }
            }
          }

          if( p.triggerEvent ){
            self[ p.triggerFnName ]( p.event );
          }
        }

        return self; // maintain chaining
      }; // function
    }
231869
function() {
      var args = Array.prototype.slice.call(arguments),
          text = args.shift();
      return text.replace(/\{(\d+)\}/g, function(match, number) {
        return typeof args[number] !== 'undefined' ? args[number] : match;
      });
    }
757127
function getValidOptions (options, setDefaults) {
    // make sure options is object
    options = requireValidOptionalObject(options)
    // validate automock if passed
    if (defined(options.automock)) {
        if (typeof options.automock !== 'function') {
            throw new Error('options error: automock must be function')
        }
    }
    // validate cache client if passed
    if (defined(options.cacheClient)) {
        requireValidCacheClient(options.cacheClient)
    }
    // validate log client if passed
    if (defined(options.logClient)) {
        requireValidLogClient(options.logClient)
    }

    // do not set default values unless flag set
    if (!setDefaults) {
        return options
    }

    // set defaults
    _.each(defaultOptions, (defaultOptionName, optionName) => {
        if (!defined(options[optionName])) {
            options[optionName] = immutable[defaultOptionName]
        }
    })

    // return options
    return options
}
182126
def evaluate_default_value(val)
      if val.respond_to?(:call)
        val.call
      elsif val.duplicable?
        val.dup
      else
        val
      end
    end
484179
function getValidOptions (options) {
  if (typeof options !== 'object') {
    return DEFAULT_OPTIONS
  }

  var validOptions = {}

  for (var prop in DEFAULT_OPTIONS) {
    if (DEFAULT_OPTIONS.hasOwnProperty(prop)) {
      validOptions[prop] = typeof options[prop] === 'string'
        ? options[prop] : DEFAULT_OPTIONS[prop]
    }
  }

  return validOptions
}
1234777
def get_parameter(self, name, default=None):
        '''
        
        '''
        if hasattr(self, name):
            item = getattr(self, name)
            if isinstance(item, Parameter):
                return item
        return default
818399
function validate() {
  const errors = [].concat(
    _validateStore(),
    _validatePassword(),
    _validateThemeId(),
  );

  return {
    errors,
    isValid: errors.length === 0,
  };
}
176761
function generateValidationFn(schema) {
        return function (req) {

            // if already an error, return without doing any additional validation
            if (req.error) { return req; }

            var keys = Object.keys(schema);
            var len = (req.value && req.value.trim().length) || 0;
            var i, key, originalKey;

            for (i = 0; i < keys.length; i++) {
                key = originalKey = keys[i];
                if (key.indexOf('ui-') === 0) {
                    key = key.substring(3);
                }

                // if validation function exists but it returns false then we have error
                if (check[key] && !check[key](schema, req.value)) {
                    var errMsg = schema[key + 'Desc'] || errorMessage[key] || 'Invalid input';
                    req.error = errMsg
                        .replace('{' + key + '}', schema[originalKey])
                        .replace('{value}', req.value)
                        .replace('{length}', len);
                    break;
                }
            }

            return req;
        };
    }
1221948
function getValidationFunction (validationOptions) {
        validationOptions = validationOptions || {};

        return function (doc, schema, options) {
            doc = doc || {};
            options = options || {};
            options.isUpdate = options.isUpdate || false;

            // check is update
            if (options.isUpdate) {
                var i,
                    keys = Object.keys(schema.properties),
                    length = keys.length;

                for (i = 0; i < length; i++) {
                    if (!doc.hasOwnProperty(keys[i])) {
                        // set property required to false
                        schema.properties[keys[i]].required = false;

                        // remove property from required array
                        if (Array.isArray(schema.required) && schema.required.indexOf(keys[i]) > -1) {
                            schema.required.splice(schema.required.indexOf(keys[i]), 1);
                        }
                    }
                }
            }

            // add default validation options to options object
            for (var key in validationOptions) {
                // only add options, do not override
                if (validationOptions.hasOwnProperty(key) && !options.hasOwnProperty(key)) {
                    options[key] = validationOptions[key];
                }
            }

            // json schema validate
            return exports.validate(doc, schema, options);
        };
    }
350900
def value_or_default(self, value):
        '''  '''
        if value is None:
            if callable(self.default):
                return self.default()
            else:
                return self.default

        return value
549133
function getTemplate(val, defaultVal) {
  if(isFunction(val)) {
    return val(cloneDeep(defaultVal));
  }
  else if(isArray(val)) {
    return val;
  }
  else {
    return cloneDeep(defaultVal);
  }
}
109142
function getPropDefaultValue (vm, prop, key) {
  // no default, return undefined
  if (!hasOwn(prop, 'default')) {
    return undefined
  }
  var def = prop.default;
  // warn against non-factory defaults for Object & Array
  if (isObject(def)) {
    warn(
      'Invalid default value for prop "' + key + '": ' +
      'Props with type Object/Array must use a factory function ' +
      'to return the default value.',
      vm
    );
  }
  // the raw prop value was also undefined from previous render,
  // return previous default value to avoid unnecessary watcher trigger
  if (vm && vm.$options.propsData &&
    vm.$options.propsData[key] === undefined &&
    vm._props[key] !== undefined
  ) {
    return vm._props[key]
  }
  // call factory function for non-Function types
  // a value is Function if its prototype is function even across different execution context
  return typeof def === 'function' && getType(prop.type) !== 'Function'
    ? def.call(vm)
    : def
}
1162502
function toDefault(val, def) {
    if (is_1.isValue(val) && !(is_1.isEmpty(val) && !is_1.isEmpty(def)))
        return val;
    return is_1.isValue(def) ? def : null;
}
1300306
function (key, defaultValue) {
            var input = self.session.get('_old_input', []);

            // Input that is flashed to the session can be easily retrieved by the
            // developer, making repopulating old forms and the like much more
            // convenient, since the request's previous input is available.
            if (key) {
                return isset(input[key]) ? input[key] : defaultValue;
            } else {
                return input;
            }
        }
594015
def get(self, option, default=undefined, cast=undefined):
        

        # We can't avoid __contains__ because value may be empty.
        if option in os.environ:
            value = os.environ[option]
        elif option in self.repository:
            value = self.repository[option]
        else:
            if isinstance(default, Undefined):
                raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))

            value = default

        if isinstance(cast, Undefined):
            cast = self._cast_do_nothing
        elif cast is bool:
            cast = self._cast_boolean

        return cast(value)