Skip to content

Instantly share code, notes, and snippets.

@dmail
Last active January 5, 2024 11:09
Show Gist options
  • Save dmail/54677cc3eae1661813e3a87840666f83 to your computer and use it in GitHub Desktop.
Save dmail/54677cc3eae1661813e3a87840666f83 to your computer and use it in GitHub Desktop.
URL parts naming. Inspired from web browsers API (new URL(), window.location) and rfc3986.
/*
href
┌────────────────────────────────────────┴──────────────────────────────────────────────┐
origin │
┌────────────┴──────────────┐ │
│ authority │
│ ┌───────────────┴───────────────────────────┐ │
│ │ host resource
│ │ ┌──────────┴─────────────────┐ ┌────────────┴───────────┬───────┐
│ │ hostname │ pathname │ │
│ │ ┌──────────────┴────────────┐ │ ┌──────┴───────┐ │ │
protocol userinfo subdomain domain │ │ filename │ │
┌─┴──┐ ┌───┴────┐ │ ┌────────┴───────┐ │ │ ┌───┴─────┐ │ │
scheme │username password lowerleveldomains secondleveldomain topleveldomain port dirname basename extension search hash
┌──┴───┐│┌──┴───┐ ┌──┴───┐ ┌──┬─┬─┴─────┬───┐┌───────┴───────┐ ┌──────┴──────┐┌─┴┐┌────┴──────┐┌──┴───┐ ┌───┴───┐ ┌────┴────┐ ┌┴┐
│ │││ │ │ │ │ │ │ │ ││ │ │ ││ ││ ││ │ │ │ │ │ │ │
scheme://username:[email protected]:1234/hello/world/basename.extension?name=ferret#hash
*/
@dmail
Copy link
Author

dmail commented Aug 1, 2022

A more detailed description about this gist.

I have created this gist to list and identify all urls parts.
The names are meant to name JavaScript variables or identify what a JavaScript variable refers to.
For this reason names are coming first from URL Web API. Then all blanks left by URL web API are filled using rfc3986.

It results in the 2 differences mentioned in gistcomment-4251501

  • "search" from web APIs is favored over "query" from rfc3986
  • "hash" from web APIs is favored over "fragment" from rfc3986

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment