Convert String to URL params string - Node.js Network

Node.js examples for Network:URL

Description

Convert String to URL params string

Demo Code

String.prototype.escape = function( find ) {
    return this.replace( new RegExp( find, 'g' ), '\\' + find );
};

String.prototype.appendParams = function( params ) {
    var updatedString = this;
    for ( var key in params ) {
        if ( updatedString.indexOf( key + '=' ) > -1 )
            continue;// w w w .  j a  va 2  s .  c  om

        if ( updatedString.indexOf( '?' ) > -1 )
            updatedString += '&' + key + '=' + params[key];
        else
            updatedString += '?' + key + '=' + params[key];
    }
    return updatedString;
};

Related Tutorials