JSFiddle - React, Tailwind, and code Playground
by John Wick
JavaScript
function isHttp2(url) {
if (url) {
if (!/^(https?:)?\/\//i.test(url)) {
url = 'https://' + url;
}
return url;
}
}
var urls = [
undefined,
"",
"abc.com",
"http://def.com",
"www.hij.com",
"https://klm.com",
"HTTP://CNN.com",
"abc.com/path1/path2/path3",
];
for (let i=0; i<urls.length; i++) {
console.log(`${urls[i]} = ${isHttp2(urls[i])}`);
}