Last active
September 29, 2019 18:18
-
-
Save mahfelwp/8ba92cf2e0a26a5e703afa02d5d3b3ff to your computer and use it in GitHub Desktop.
Simple function for work with Url in Javascript without regxp
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
// For more information you can see this url: https://developer.mozilla.org/en-US/docs/Web/API/URL | |
let parseUrl = (url) => { | |
let parser = document.createElement('a'); | |
parser.href = url; | |
return parser; | |
} | |
let url = parseUrl("http://username:[email protected]:3000/deploy/?search=test#hash"); | |
url.protocol; // => "http:" | |
url.host; // => "example.com:3000" | |
url.hostname; // => "example.com" | |
url.port; // => "3000" | |
url.pathname; // => "/deploy/" | |
url.hash; // => "#hash" | |
url.search; // => "?search=test" | |
url.origin; // => "http://example.com:3000" | |
url.username; // => "username" | |
url.password; // => "password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment