AddSlash ('-' * 8) Wanted to create a function that added a slash to a url path, but only if it was needed. Also wanted it to be able to ignore any query string items
Last active
August 29, 2015 14:21
-
-
Save kenwilcox/e082c07dc5ba3a1f616d to your computer and use it in GitHub Desktop.
AddSlash
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
var urls = [ | |
'http://mydomain.com', | |
'http://mydomain.com?key=value', | |
'http://mydomain.com/', | |
'http://mydomain.com/?key=value', | |
'http://mydomain.com/api', | |
'http://mydomain.com/api?key=value', | |
'http://mydomain.com/api/', | |
'http://mydomain.com/api/?key=value', | |
'check', | |
'1842', | |
]; | |
for(var i=0; i<urls.length; i++) { | |
$('body').append(urls[i].replace(/\/?(\?|#|$)/, '/$1') + '<br />'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment