Skip to content

Instantly share code, notes, and snippets.

@sam-rad
Created October 24, 2019 17:22
Show Gist options
  • Save sam-rad/abf95212d6f670d6603651b1082a04ae to your computer and use it in GitHub Desktop.
Save sam-rad/abf95212d6f670d6603651b1082a04ae to your computer and use it in GitHub Desktop.
Wildcard URL parsing in node, chrome and firefox
// Chrome
new URL('https://*.bee.com');
// URL {
// hash: ""
// host: "%2A.bee.com" // <= Escaped
// hostname: "%2A.bee.com"
// href: "https://%2A.bee.com/"
// origin: "https://%2A.bee.com"
// password: ""
// pathname: "/"
// port: ""
// protocol: "https:"
// search: ""
// searchParams: URLSearchParams {}
// username: ""
// }
// Firefox
new URL('https://*.bee.com');
// TypeError: https://*.bee.com is not a valid URL
// Node
new URL('https://*.bee.com');
// URL {
// href: 'https://*.bee.com/',
// origin: 'https://*.bee.com',
// protocol: 'https:',
// username: '',
// password: '',
// host: '*.bee.com',
// hostname: '*.bee.com',
// port: '',
// pathname: '/',
// search: '',
// searchParams: URLSearchParams {},
// hash: ''
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment