Last active
April 12, 2018 03:37
-
-
Save cyio/30f79a566c236751057a11956692c7a6 to your computer and use it in GitHub Desktop.
parse 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
// only work in browser environment | |
export const parseUrl = url => { | |
const a = document.createElement('a') | |
a.href = url | |
return { | |
href: a.href, | |
protocol: a.protocol, | |
host: a.host, | |
hostname: a.hostname, | |
port: a.port, | |
pathname: a.pathname, | |
search: a.search, | |
hash: a.hash, | |
origin: a.origin, | |
} | |
} | |
let result = parseUrl('http://exploringjs.com/es6/ch_destructuring.html') | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment