Last active
December 19, 2015 18:29
-
-
Save aruss/5999464 to your computer and use it in GitHub Desktop.
Generate URI with path and query http://jsfiddle.net/aruss/wfCLT/1/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!String.prototype.toUrl) { | |
String.prototype.toUrl = function(o) { | |
var r = this.replace(/\{([^{}]*)\}/g,function (a, b) { | |
var r = o[b]; | |
delete o[b]; | |
return typeof r === 'string' || typeof r === 'number' ? r : a; | |
} | |
), p = []; | |
for (var k in o) { | |
if (o[k] !== undefined && o[k] !== null) { | |
var v = o[k]; | |
if (isNaN(v)) | |
v = escape(v); | |
p.push(k + '=' + v); | |
} | |
} | |
return r + ((p.length > 0) ? '?' + p.join('&') : ''); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i like.