lib/route.js
function normalizePath(path, keys, params) {
        for (var name in params) {
            var param = params[name];
            if (typeof param == "string" || param instanceof RegExp)
                params[name] = {type: param};
        }

        path = path
            .concat("/?")
            .replace(/\/:([\w.\-_]+)(\*?)/g, function(match, key, wildcard) {
                keys.push(key);
                if (!params[key]) {
                    params[key] = {};
                }
                // url params default to type string and optional=false
                var param = params[key];
                param.type = param.type || "string";
                param.optional = false;

                if (!param.source) param.source = "url";

                if (param.source !== "url")
                    throw new Error(
                        "Url parameters must have 'url' as source but found '" +
                            param.source +
                            "'"
                    );

                if (wildcard) return "(/*)";
                else return "/([^\\/]+)";
            })
            .replace(/([/.])/g, "\\$1")
            .replace(/\*/g, "(.*)");

        return new RegExp("^" + path + "$");
    }
function normalizePath(path, keys, params) {
        for (var name in params) {
            var param = params[name];
            if (typeof param == "string" || param instanceof RegExp)
                params[name] = {type: param};
        }

        path = path
            .concat("/?")
            .replace(/\/:([\w.\-_]+)(\*?)/g, function(match, key, wildcard) {
                keys.push(key);
                if (!params[key]) {
                    params[key] = {};
                }
                // url params default to type string and optional=false
                var param = params[key];
                param.type = param.type || "string";
                param.optional = false;

                if (!param.source) param.source = "url";

                if (param.source !== "url")
                    throw new Error(
                        "Url parameters must have 'url' as source but found '" +
                            param.source +
                            "'"
                    );

                if (wildcard) return "(/*)";
                else return "/([^\\/]+)";
            })
            .replace(/([/.])/g, "\\$1")
            .replace(/\*/g, "(.*)");

        return new RegExp("^" + path + "$");
    }
function normalizePath ( path , keys , params ) { for ( var name in params ) { var param = params [ name ] ; if ( typeof param == "string" || param instanceof RegExp ) params [ name ] = { type : param } ; } path = path . concat ( "/?" ) . replace ( / \/:([\w.\-_]+)(\*?) / g , function ( match , key , wildcard ) { keys . push ( key ) ; if ( ! params [ key ] ) { params [ key ] = { } ; } // url params default to type string and optional=false var param = params [ key ] ; param . type = param . type || "string" ; param . optional = false ; if ( ! param . source ) param . source = "url" ; if ( param . source !== "url" ) throw new Error ( "Url parameters must have 'url' as source but found '" + param . source + "'" ) ; if ( wildcard ) return "(/*)" ; else return "/([^\\/]+)" ; } ) . replace ( / ([/.]) / g , "\\$1" ) . replace ( / \* / g , "(.*)" ) ; return new RegExp ( "^" + path + "$" ) ; }
Creates a rgular expression to match this route.
Url param names are stored in `keys` and the `params` are completed with
the default values for url parameters.
Creates a rgular expression to match this route . Url param names are stored in keys and the params are completed with the default values for url parameters .