lib/Hecate.js
function(url, val){

        // Create a new object that we can manipulate safely.
        var object = extend({}, val);

        // Flag so we remember to append any attributes that can't be bound.
        var append = false;

        // If there are still parameters to bind, pull them out.
        // Note: We use a different regex here because we need the global flag to ensure we pull all remaining bindings.
        var remaining = url.match(/:\w+/ig);
        if (remaining && remaining.length > 0){

            // Iterate over the remaining potential bindings, looking for matches by name.
            for (var j = 0; j < remaining.length; j++){

                // Grab the key, stripping the : character.
                var key = remaining[j].replace(':', '');

                // Does our object contain that key?
                if (object[key] !== undefined){

                    // Is it a type we can serialise?
                    if (this.canSerialise(object[key])){

                        // If it is, replace that value.
                        var keyRegex = new RegExp(':' + key);
                        url = url.replace(keyRegex, object[key]);
                    }

                    // Even if it wasn't, delete the value so we don't try again later.
                    delete object[key];
                }
            }

            // If there are still fields left on our object, they need to become query parameters.
            if (object !== {}){
                append = true;
            }
        }

        // Otherwise, we're going to append the object's values as key/value pairs.
        else {
            append = true;
        }

        // If we need to append key/values, do so.
        if (append){

            for (var attr in object){

                // If the value is an object or a function, ignore it.
                if (this.canSerialise(object[attr])){

                    // How are we appending?
                    var joiner = (url.indexOf('?') >= 0) ? "&" : "?";

                    // Append.
                    url += joiner + attr + "=" + object[attr];
                }
            }
        }

        return url;
    }
function(url, val){

        // Create a new object that we can manipulate safely.
        var object = extend({}, val);

        // Flag so we remember to append any attributes that can't be bound.
        var append = false;

        // If there are still parameters to bind, pull them out.
        // Note: We use a different regex here because we need the global flag to ensure we pull all remaining bindings.
        var remaining = url.match(/:\w+/ig);
        if (remaining && remaining.length > 0){

            // Iterate over the remaining potential bindings, looking for matches by name.
            for (var j = 0; j < remaining.length; j++){

                // Grab the key, stripping the : character.
                var key = remaining[j].replace(':', '');

                // Does our object contain that key?
                if (object[key] !== undefined){

                    // Is it a type we can serialise?
                    if (this.canSerialise(object[key])){

                        // If it is, replace that value.
                        var keyRegex = new RegExp(':' + key);
                        url = url.replace(keyRegex, object[key]);
                    }

                    // Even if it wasn't, delete the value so we don't try again later.
                    delete object[key];
                }
            }

            // If there are still fields left on our object, they need to become query parameters.
            if (object !== {}){
                append = true;
            }
        }

        // Otherwise, we're going to append the object's values as key/value pairs.
        else {
            append = true;
        }

        // If we need to append key/values, do so.
        if (append){

            for (var attr in object){

                // If the value is an object or a function, ignore it.
                if (this.canSerialise(object[attr])){

                    // How are we appending?
                    var joiner = (url.indexOf('?') >= 0) ? "&" : "?";

                    // Append.
                    url += joiner + attr + "=" + object[attr];
                }
            }
        }

        return url;
    }
function ( url , val ) { // Create a new object that we can manipulate safely. var object = extend ( { } , val ) ; // Flag so we remember to append any attributes that can't be bound. var append = false ; // If there are still parameters to bind, pull them out. // Note: We use a different regex here because we need the global flag to ensure we pull all remaining bindings. var remaining = url . match ( / :\w+ / ig ) ; if ( remaining && remaining . length > 0 ) { // Iterate over the remaining potential bindings, looking for matches by name. for ( var j = 0 ; j < remaining . length ; j ++ ) { // Grab the key, stripping the : character. var key = remaining [ j ] . replace ( ':' , '' ) ; // Does our object contain that key? if ( object [ key ] !== undefined ) { // Is it a type we can serialise? if ( this . canSerialise ( object [ key ] ) ) { // If it is, replace that value. var keyRegex = new RegExp ( ':' + key ) ; url = url . replace ( keyRegex , object [ key ] ) ; } // Even if it wasn't, delete the value so we don't try again later. delete object [ key ] ; } } // If there are still fields left on our object, they need to become query parameters. if ( object !== { } ) { append = true ; } } // Otherwise, we're going to append the object's values as key/value pairs. else { append = true ; } // If we need to append key/values, do so. if ( append ) { for ( var attr in object ) { // If the value is an object or a function, ignore it. if ( this . canSerialise ( object [ attr ] ) ) { // How are we appending? var joiner = ( url . indexOf ( '?' ) >= 0 ) ? "&" : "?" ; // Append. url += joiner + attr + "=" + object [ attr ] ; } } } return url ; }
Handles binding the fields of an object into a URL.
@param {string} url The URL to bind against.
@param {object} val The object from which to draw properties.
@return {string} The updated URL.
Handles binding the fields of an object into a URL .