Skip to main content

Implementação

URL válida

function isValidUrl(string) {
try {
new URL(string);
return true;
} catch (err) {
return false;
}
}

URL canParse

  URL.canParse("https://webtoolsweekly.com");

Construir URL

new URL('/about-2', request.url)
//caminho //url base

Validando String null, undefined ou vazia

function checkIfEmpty(str) {
if (str) {
console.log('String is NOT empty');
} else {
console.log('String is empty');
}
}
const str1 = 'not empty';
const str2 = ''; // empty
const str3 = null;
const str4 = undefined;

checkIfEmpty(str1); // outputs: String is NOT empty
checkIfEmpty(str2); // outputs: String is empty
checkIfEmpty(str3); // outputs: String is empty
checkIfEmpty(str4); // outputs: String is empty