Last active
December 15, 2016 09:28
-
-
Save Kydoh/715d74c88494fe11116821233e2ad53a to your computer and use it in GitHub Desktop.
Parse a given URL.
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
/** | |
* Parse a given URL. | |
* | |
* @param {string} url | |
* @return {Object} | |
*/ | |
function parseUrl(url) | |
{ | |
var parser = document.createElement('a'); | |
parser.href = url; | |
return { | |
hash: parser.hash.substr(1), | |
host: parser.hostname, | |
path: parser.pathname, | |
port: parser.port, | |
protocol: parser.protocol.slice(0, -1), | |
query: parser.search.substr(1) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment