Skip to content

Instantly share code, notes, and snippets.

@rinogo
Created April 12, 2022 02:55
Show Gist options
  • Save rinogo/cee6ec7ff300ebb45b1e989f140afcea to your computer and use it in GitHub Desktop.
Save rinogo/cee6ec7ff300ebb45b1e989f140afcea to your computer and use it in GitHub Desktop.
[Convert URLs to origins (domains)] Convert a list of full URLs into just origins (just the base domains with the protocols)
//Convert a list of full URLs into just origins (just the base domains with the protocols)
let s = '';
['https://www.whatever.com/narf',
'https://beta.something.co.uk/?3920#fjfjf'].map((u) => {
let url = new URL(u);
s += url.origin + '\n';
});
console.log(s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment