Created
September 10, 2020 22:09
-
-
Save satty1987/da2b5091c1c796d0e88f5d1f4303dc44 to your computer and use it in GitHub Desktop.
URL Query Builder
This file contains 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
replaceParams (endPoint, params) { | |
if (angular.isString(endPoint)) { | |
if (params) { | |
angular.forEach(params, function (val, key) { | |
endPoint = endPoint.replace('[' + key + ']', val); //First look for optional params | |
endPoint = endPoint.replace('{' + key + '}', val); | |
}); | |
} | |
endPoint = endPoint.replace(/(\[[^\[]*\])/g, ''); //Replace undefined optional param holders | |
endPoint = endPoint.replace(/\/\//, '/'); //Replace '//' if any with '/' | |
endPoint = endPoint.replace(/(\/)$/, ''); //Remove trailing '/' | |
} | |
return endPoint; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment