Skip to content

Instantly share code, notes, and snippets.

@no1xsyzy
Created June 30, 2017 07:51
Show Gist options
  • Save no1xsyzy/7cbbba5f78c96e274d09999c4e7cfcaa to your computer and use it in GitHub Desktop.
Save no1xsyzy/7cbbba5f78c96e274d09999c4e7cfcaa to your computer and use it in GitHub Desktop.
Function for parsing URLs
window.parseURL=function(URL){
let [,schema="",host="",path="",search="",hash=""]=
URL.match(/^(?:(?:([^:]+:)?\/\/)?([^\/#?]+))?(?:(\/[^#?]*)?(\?[^#]*)?(#.*)?)?$/);
return {schema,host,path,search,hash}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment