Skip to content

Instantly share code, notes, and snippets.

@cyio
Last active April 12, 2018 03:37
Show Gist options
  • Save cyio/30f79a566c236751057a11956692c7a6 to your computer and use it in GitHub Desktop.
Save cyio/30f79a566c236751057a11956692c7a6 to your computer and use it in GitHub Desktop.
parse url
// 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