Created
January 10, 2019 22:23
-
-
Save pastranastevenaz/fd5c639130975c64ac84279d3fc572ab to your computer and use it in GitHub Desktop.
Clean a URL with Javascript
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
| cleanUrl: function (dirtyURL){ | |
| var a = dirtyURL.toLowerCase(); | |
| if (a.startsWith("http") ) { | |
| a = a.split('/')[2]; | |
| a = a | |
| .replace('https', '') | |
| .replace('http', '') | |
| .replace('www.', '') | |
| .replace('://', '') | |
| .replace(/\/$/, '') | |
| return a; | |
| } else if(a.startsWith("www.")){ | |
| a = a | |
| .replace('https', '') | |
| .replace('http', '') | |
| .replace('www.', '') | |
| .replace('://', '') | |
| .replace(/\/$/, '') | |
| return a; | |
| } else { | |
| return a; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment