Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
import { normalizeWhoisField } from './normalize-whois-entry';
// Normalize a WHOIS URL.
export function normalizeWhoisURL( url: string | string[] | undefined ): string {
let normalisedURL = normalizeWhoisField( url );
if ( normalisedURL === '' ) {
return normalisedURL;
}
// Add a protocol if one is missing (assume HTTPS).
if ( ! /^(http|https):\/\//.test( normalisedURL ) ) {
normalisedURL = `https://${ normalisedURL }`;
}
try {
// Throw an error if the URL is invalid.
const urlObject = new URL( normalisedURL );
return urlObject.href;
} catch ( error ) {
return '';
}
}