Skip to content

Instantly share code, notes, and snippets.

@bmorwood
Created April 12, 2018 12:28
Show Gist options
  • Save bmorwood/9e9535540b1f16090632b45e2f72de79 to your computer and use it in GitHub Desktop.
Save bmorwood/9e9535540b1f16090632b45e2f72de79 to your computer and use it in GitHub Desktop.
export function getUrlProps(url) {
var match = url.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
return match && {
url: url,
protocol: match[1],
host: match[2],
hostname: match[3],
port: match[4],
pathname: match[5],
search: match[6],
hash: match[7]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment