12345678910111213141516171819202122232425262728 |
- /**
- * Set query string parameter value
- */
- function setParam(url, paramName, value){
- url = url || '';
- var re = new RegExp('(\\?|&)'+ paramName +'=[^&]*' );
- var param = paramName +'='+ encodeURIComponent( value );
- if ( re.test(url) ) {
- return url.replace(re, '$1'+ param);
- } else {
- if (url.indexOf('?') === -1) {
- url += '?';
- }
- if (url.indexOf('=') !== -1) {
- url += '&';
- }
- return url + param;
- }
- }
- module.exports = setParam;
|