/*
解析依赖模块列表，如果有依赖模块则开始解析依赖模块
param { Object } 配置参数
param { Array } 依赖模块
424059
function readDeps(options, parentDeps) {
    var childDeps = [];
    parentDeps.map(function (item) {
        var id = item.id,
            extName = item.extName,
            filePath = item.path,
            origId = item.origId,
            contents, deps, isIgnore;
        isIgnore = options.ignore ?
            filterIgnore(options.ignore, id, origId) :
            false;

        // 检测该模块是否在忽略列表中
        if (isIgnore) {
            options.modArr.push({
                id: id,
                path: filePath,
                contents: '',
                extName: extName,
                origId: origId
            });
            // resolve();
            return;
        }

        // 处理普通的js模块
        if (!extName && filePath.slice(-3) !== '.js') {
            filePath += '.js';
        }

        try {
            contents = fs.readFileSync(filePath, options.encoding);
        } catch (_) {
            console.log(chalk.red(PLUGIN_NAME + ' error: File [' + filePath + '] not found.'));
            return;
        }

        deps = parseDeps(options, contents, item);
        if (deps.length) {
            for (var i = deps.length - 1; i > -1; i--) {
                var depsid = deps[i].id;
                options.modArr.forEach(function (mod) {
                    if (mod.id === depsid) {
                        deps.splice(i, 1);
                    }
                });
            }
            childDeps = childDeps.concat(deps);
        }
    });
    try {
        for (var i = childDeps.length - 1; i > -1; i--) {
            var id = childDeps[i].id;
            options.modArr.forEach(function (mod) {
                if (mod.id === id) {
                    childDeps.splice(i, 1);
                }
            });
        }
        if (childDeps.length) {
            return readDeps(options, childDeps);
        }
    } catch (err) {
        console.log(chalk.red(PLUGIN_NAME + ' error: ' + err.message));
        console.log(err.stack);
    }
}
121366
function allowOptionalParams(params, callback) {
    if (!callback) {
        callback = params;
        params = { };
    }
    return {
        params: params,
        callback: callback,
    };
}
824103
function paramParser(rawParams) {
    if (rawParams === void 0) { rawParams = ''; }
    var /** @type {?} */ map = new Map();
    if (rawParams.length > 0) {
        var /** @type {?} */ params = rawParams.split('&');
        params.forEach(function (param) {
            var /** @type {?} */ eqIdx = param.indexOf('=');
            var _a = eqIdx == -1 ? [param, ''] : [param.slice(0, eqIdx), param.slice(eqIdx + 1)], key = _a[0], val = _a[1];
            var /** @type {?} */ list = map.get(key) || [];
            list.push(val);
            map.set(key, list);
        });
    }
    return map;
}
1002103
function queryParamsState(queryParamsArray, controller) {
  return queryParamsArray.reduce(
    (state, qp) => {
      let value = qp.value(controller);

      state[qp.key] = {
        value,
        serializedValue: qp.serializedValue(controller),
        as: qp.as,
        defaultValue: qp.defaultValue,
        changed: JSON.stringify(value) !== JSON.stringify(qp.defaultValue)
      };
      return state;
    },
    {},
    undefined
  );
}
196085
function(params) {
			var newparams = ''; 
			
			for (par in params) {
				var obj = params[par];
				if(typeof obj ==  'string'){
					if (params[par]) {
						if(newparams)newparams += "&";
						newparams += par + "=" + params[par];
					}
				}else if(obj instanceof  Array){
					if(newparams)newparams += "&";
					
					var i = 0;
					for(i=0; i<obj.length; i++){
						if (obj[i]) {
							newparams += par + "=" + obj[i];
							if(i != obj.length-1)newparams += ";";
						}
						
					}
				}
			}
			//newparams=newparams.encode();
			//encode(newparams);
			//return escape('?'+newparams);
			return encodeURI('?'+newparams); //The old version (escape('?'+newparams);) gave problems because it encoded ? and &
		}
602721
function getParams()
    {
        $params = array();
        foreach (get_object_vars($this) as $k => $v) {
            if ($k[0] == '_') {
                $params[substr($k, 1)] = $v;
            }
        }

        return $params;
    }
1131631
function paramsFromRegexPath(paramsObj) {
        var paramNames = Object.keys(paramsObj);
        var params = paramNames.reduce(function(params, paramName) {
            if ((/^\d+$/).test(paramName)) {
                params.push(paramsObj[paramName]);
            }
            return params;
        }, []);
        return params;
    }
233429
function() {
        var params = {
          where: this._where,
        };

        if (this._include.length > 0) {
          params.include = this._include.join(',');
        }
        if (this._select.length > 0) {
          params.keys = this._select.join(',');
        }
        if (this._includeACL !== undefined) {
          params.returnACL = this._includeACL;
        }
        if (this._limit >= 0) {
          params.limit = this._limit;
        }
        if (this._skip > 0) {
          params.skip = this._skip;
        }
        if (this._order !== undefined) {
          params.order = this._order;
        }

        AV._objectEach(this._extraOptions, function(v, k) {
          params[k] = v;
        });

        return params;
      }
358929
function (params) {

			return _.every(_.keys(params), function (key) { 
				return _.contains(put_params, key); 
			});
		}
692820
function Param() {
		if (arguments.length == 0) {
			throw new ERR.Arguments('1+', 0);
		}

		if (arguments.length == 1 && arguments[0] instanceof Param) {
			return arguments[0];
		}

		this.type = null;
		this.minSize = 1;
		this.maxSize = 1;
		this.nil = false;
		this.undef = false;
		this.absent = false;
		this.absentValue = undefined;
		this.arrayed = false;

		var setSize = (function(size) {
			if (typeof size == 'string') {
				// 清除所有空白字符。
				size = size.replace(/\s/g, '');
				if (size == '*' || size == '...') {
					this.minSize = 0;
					this.maxSize = Infinity;
					this.arrayed = true;
					return true;
				}
				if (size == '+') {
					this.minSize = 1;
					this.maxSize = Infinity;
					this.arrayed = true;
					return true;
				}

				// 区间形式。
				if (/^\{.+\}$/.test(size)) {
					size = size.slice(1, -1);
				}
				if (/^\d+$/.test(size)) {
					this.minSize = this.maxSize = parseInt(size);
					this.arrayed = true;
					return true;
				}
				if (/^,(\d+)$/.test(size)) {
					this.minSize = 0;
					this.maxSize = parseInt(RegExp.$1);
					this.arrayed = true;
					return true;
				}
				if (/^(\d+),$/.test(size)) {
					this.minSize = parseInt(RegExp.$1);
					this.maxSize = Infinity;
					this.arrayed = true;
					return true;
				}
				if (/^(\d+),(\d+)$/.test(size)) {
					this.minSize = parseInt(RegExp.$1);
					this.maxSize = parseInt(RegExp.$2);
					this.arrayed = true;
					return true;
				}
				return false;
			}

			if (Number.isInteger(size) && size > 0) {
				this.minSize = this.maxSize = size;
				this.arrayed = true;
				return true;
			}

			return false;
		}).bind(this);

		var type = arguments[0], decos = [];

		// ---------------------------
		// 处理特殊的参数占位符。
		if (setSize(type)) {
			this.type = Type.ANY;
			return this;
		}

		// ---------------------------
		// 处理数据类型。

		if (typeof type == 'string') {
			// 如果首参数是字符串，则它可能包括数据类型别名及修饰符，我们需要首先将其拆分。
			// 拆分后第一个字符串作为数据类型（别名，后面还会继续处理），其余作为修饰符。
			decos = type.trim().split(/\s+/);
			type = decos.shift();
		}

		this.type = Type.parse(type);

		// ---------------------------
		// 处理修饰符。

		var DECOS = ['NULL', 'UNDEFINED', 'ABSENT'], i;

		for (i = 1; i < arguments.length; i++) {
			if (typeof arguments[i] == 'string') {
				decos = decos.concat(arguments[i].trim().split(/\s+/));
			}
			else if (Number.isInteger(arguments[i])) {
				decos.push(arguments[i]);
			}

			// @tag 20180222
			else if (arguments[i] instanceof Absent) {
				this.absent = true;
				this.absentValue = arguments[i].value;
			}
		}
		
		for (i = 0; i < decos.length; i++) {
			var rawDeco = decos[i];

			// 尝试作为量化修饰符应用。
			if (setSize(rawDeco)) continue;

			// 设置缺省值。
			// 注意：为避免歧义，缺省值字面量中不得出现空格。
			// @tag 20180222
			if (/^=(.+)$/.test(rawDeco)) {
				this.absent = true;
				this.absentValue = eval(RegExp.$1);
				continue;
			}

			// 普通修饰符不区分大小写。
			decos[i] = decos[i].toUpperCase();

			// 如果修饰符不合法，须抛出异常。
			if (!has(DECOS, decos[i])) {
				throw new ERR.Range('param decorator', DECOS, rawDeco);
			}
		}

		// 为了避免可能的语法冲突，这些修饰符对应的属性名回避了 JavaScript 保留字。

		// 参数是否可以为 null
		this.nil = has(decos, 'NULL');

		// 参数是否可以为 undefined
		this.undef = has(decos, 'UNDEFINED');

		// 参数是否可以缺席。
		if (!this.absent) {
			this.absent = has(decos, 'ABSENT');
		}
	}
1059218
function getParams(obj) {
    var defs = []

    for (var name in obj) {
      var data = obj[name]
        , fromPath = ~required.indexOf(name)

      // If string, assume a single data type
      if (typeof data === 'string') {
        data = data.split(',')
      }

      // If array, assume array of data types
      if (Array.isArray(data)) {
        data = obj[name] = {
          dataTypes: data
        }
      }

      // Check for singular spelling
      if (data.dataType) {
        data.dataTypes = data.dataType
      }

      // Ensure datatypes is an array
      if (!Array.isArray(data.dataTypes)) {
        data.dataTypes = [data.dataTypes]
      }

      // Normalize data types
      var types = _.uniq((data.dataTypes || []).map(function(type) {
        return type && type.toLowerCase()
      }))

      // Parameter type / source
      var paramType = 'path'
      if (!fromPath) {
        // If not a URI param, check to see if a `post` source
        // was specified, otherwise default to `querystring`
        paramType = (data.paramType && data.paramType === 'post')
          ? 'post'
          : 'querystring'
      }

      // Parameter spec information
      var param = {
        name: name
      , required: fromPath ? true : !!data.required
      , paramType: paramType
      , dataTypes: types
      }

      // If we have a number, check if a min / max value was set
      if (~types.indexOf('number')) {
        if (_.has(data, 'min')) param.min = +data.min;
        if (_.has(data, 'max')) param.max = +data.max;
      }

      // Add in any extra information defined from options
      if (self.options.paramProperties) {
        self.options.paramProperties.forEach(function(prop) {
          if (_.has(data, prop)) {
            param[prop] = data[prop]
          }
        })
      }

      // If we have an object type, check for sub-schemas
      if (~types.indexOf('object') && data.params) {
        param.params = getParams(data.params)
      }

      defs.push(param)
    }
    return defs
  }
869338
function (param, idx, all) {
        // helps handle weird edge cases such as "/get?a=b&&"
        if (param === EMPTY && // if param is empty
            _.isNumber(idx) && // this and the next condition ensures that this is part of a map call
            _.isArray(all) &&
            idx !== (all && (all.length - 1))) { // not last parameter in the array
            return { key: null, value: null };
        }

        var index = (typeof param === STRING) ? param.indexOf(EQUALS) : -1,
            paramObj = {};

        // this means that there was no value for this key (not even blank, so we store this info) and the value is set
        // to null
        if (index < 0) {
            paramObj.key = param.substr(0, param.length);
            paramObj.value = null;
        }
        else {
            paramObj.key = param.substr(0, index);
            paramObj.value = param.substr(index + 1);
        }

        return paramObj;
    }
55545
function (param) {
        if (!param || param.disabled) { return ''; }
        var unparsed = param.key || '';

        // if the value is not falsy, then we add the value
        // @note - The "param.value != null" check is basically !_.isNil(). (isNil is not available in lodash v3.x)
        // This is the right thing to use here.
        (param.value !== null) && (unparsed += ('=' + (param.value || '')));

        return unparsed;
    }
212860
function parseParams(params, init) {
  return reduce(params, function(obj, param) {
    var parts = param.split(/ *= */);
    var key = removeQuote(parts[0]);
    obj[key] = removeQuote(parts[1]);
    return obj;
  }, init);
}
196941
function (param) {
        var split = param.split('='),
            key, value;
        key = split[0].trim();
        value = (split[1]) ? split[1].trim() : true;

        if (_.isString(value) && value[0] === '"') {
            value = value.slice(1, -1);
        }

        return { key: key, value: value };
    }
473709
function makeType(param) {
	//console.log('makeType',param);
	param = Array.isArray(param)? param[0]: param;
	var strarr = [];
	if (param.format) {
	    strarr.push(formatType(param.format));
	    if ( Array.isArray(param.type) && param.type.indexOf('null') !== -1 ) {
            strarr.push('Null');
	    }
	    return strarr.join('/');
	}
	var str = '';
	if (Array.isArray(param.type)) {
        param.type.map(function(type){
            str = type;
            if (str === 'array') {
                str = makeType(param.items)+'[]';
            }
            strarr.push(formatType(str));
        });
        return strarr.join('/');
	} else if (param.type) {
	    str = param.type
	    if (str === 'array') {
    		str = makeType(param.items)+'[]';
    	}
    	return formatType(str);
	}

	return 'Unknown';
}
335592
function _param(req, param, pdefault){

    var ret = null;

    // Try the route parameter space.
    if( req && req.params && typeof(req.params[param]) !== 'undefined' ){
	ret = req.params[param];
    }

    // Try the get space.
    if( ! ret ){

	if( req && req.query && req.query[param] && typeof(req.query[param]) !== 'undefined' ){
	    ret = req.query[param];
	}
    }

    // Otherwise, try the body space.
    if( ! ret ){

	var decoded_body = req.body || {};
	if( decoded_body && ! us.isEmpty(decoded_body) && decoded_body[param] ){
	    ret = decoded_body[param];
	}
    }

    // Reduce to first if array.
    if( us.isArray(ret) ){
	if( ret.length === 0 ){
	    ret = pdefault;
	}else{
	    ret = ret[0];
	}
    }

    // Finally, default.
    if( ! ret ){
	ret = pdefault;
    }

    return ret;
}