lib/escort-client.js
function (route, converters) {
        var literals = route.literals;
        var params = route.params;
        
        var conv = [];
        
        var fun = "";
        fun += "var generate = function (params) {\n";
        fun += "    if (arguments.length === 1 && typeof params === 'object' && params.constructor !== String) {\n";
        fun += "        return ";
        fun += JSON.stringify(literals[0]);
        for (var i = 0, len = params.length; i < len; i += 1) {
            fun += "+converters[";
            fun += i;
            fun += "](params[";
            fun += JSON.stringify(params[i].name);
            fun += "])";
            if (literals[i + 1]) {
                fun += "+";
                fun += JSON.stringify(literals[i + 1]);
            }
            
            var paramType = params[i].type;
            if (!has.call(converters, paramType)) {
                throw new Error("Unknown converter: " + paramType);
            }
            
            var converter = converters[paramType];
            if (!converter) {
                throw new Error("Misconfigured converter: " + paramType);
            }
            
            conv.push(converter(params[i]));
        }
        fun += ";\n";
        fun += "    }\n";
        fun += "    return generate({";
        
        for (i = 0, len = params.length; i < len; i += 1) {
            if (i > 0) {
                fun += ", ";
            }
            fun += JSON.stringify(params[i].name);
            fun += ":arguments[";
            fun += i;
            fun += "]";
        }
        
        fun += "});\n";
        fun += "};\n";
        fun += "return generate;\n";
        return new Function("converters", fun)(conv);
    }
function (route, converters) {
        var literals = route.literals;
        var params = route.params;
        
        var conv = [];
        
        var fun = "";
        fun += "var generate = function (params) {\n";
        fun += "    if (arguments.length === 1 && typeof params === 'object' && params.constructor !== String) {\n";
        fun += "        return ";
        fun += JSON.stringify(literals[0]);
        for (var i = 0, len = params.length; i < len; i += 1) {
            fun += "+converters[";
            fun += i;
            fun += "](params[";
            fun += JSON.stringify(params[i].name);
            fun += "])";
            if (literals[i + 1]) {
                fun += "+";
                fun += JSON.stringify(literals[i + 1]);
            }
            
            var paramType = params[i].type;
            if (!has.call(converters, paramType)) {
                throw new Error("Unknown converter: " + paramType);
            }
            
            var converter = converters[paramType];
            if (!converter) {
                throw new Error("Misconfigured converter: " + paramType);
            }
            
            conv.push(converter(params[i]));
        }
        fun += ";\n";
        fun += "    }\n";
        fun += "    return generate({";
        
        for (i = 0, len = params.length; i < len; i += 1) {
            if (i > 0) {
                fun += ", ";
            }
            fun += JSON.stringify(params[i].name);
            fun += ":arguments[";
            fun += i;
            fun += "]";
        }
        
        fun += "});\n";
        fun += "};\n";
        fun += "return generate;\n";
        return new Function("converters", fun)(conv);
    }
function ( route , converters ) { var literals = route . literals ; var params = route . params ; var conv = [ ] ; var fun = "" ; fun += "var generate = function (params) {\n" ; fun += "    if (arguments.length === 1 && typeof params === 'object' && params.constructor !== String) {\n" ; fun += "        return " ; fun += JSON . stringify ( literals [ 0 ] ) ; for ( var i = 0 , len = params . length ; i < len ; i += 1 ) { fun += "+converters[" ; fun += i ; fun += "](params[" ; fun += JSON . stringify ( params [ i ] . name ) ; fun += "])" ; if ( literals [ i + 1 ] ) { fun += "+" ; fun += JSON . stringify ( literals [ i + 1 ] ) ; } var paramType = params [ i ] . type ; if ( ! has . call ( converters , paramType ) ) { throw new Error ( "Unknown converter: " + paramType ) ; } var converter = converters [ paramType ] ; if ( ! converter ) { throw new Error ( "Misconfigured converter: " + paramType ) ; } conv . push ( converter ( params [ i ] ) ) ; } fun += ";\n" ; fun += "    }\n" ; fun += "    return generate({" ; for ( i = 0 , len = params . length ; i < len ; i += 1 ) { if ( i > 0 ) { fun += ", " ; } fun += JSON . stringify ( params [ i ] . name ) ; fun += ":arguments[" ; fun += i ; fun += "]" ; } fun += "});\n" ; fun += "};\n" ; fun += "return generate;\n" ; return new Function ( "converters" , fun ) ( conv ) ; }
Dynamically create a url-generation function.

@param {Object} route A descriptor for the route in question
@param {Object} converters A map of converter name to converter factory.
@return {Function} A function which will generate a URL.
@api private

@example generateUrlFunction({ literals: ["/prefix"], params: [ { name: "name", type: "string" } ] })({name: "hey"}) === "/prefix/hey"
Dynamically create a url - generation function .