JSFiddle - React, Tailwind, and code Playground

by denisz

JavaScript

const isURL = (str) => {
  const regex = /^https?/gm;
  if(regex.test(str)) {
    return new URL(str);
  }

  return  new URL(`https://${str}`);
}
console.log(isURL('https://google.com'))
console.log(isURL('//google.com'))