2021-04-06 10:56:21 +02:00
|
|
|
/// Returns a normalized host of a (maybe) url without a leading www.
|
|
|
|
String normalizeInstanceHost(String maybeUrl) {
|
2021-03-31 21:28:46 +02:00
|
|
|
try {
|
2021-04-06 10:56:21 +02:00
|
|
|
return urlHost(
|
|
|
|
maybeUrl.startsWith('https://') ? maybeUrl : 'https://$maybeUrl');
|
|
|
|
} on FormatException {
|
2021-03-31 21:28:46 +02:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 20:53:09 +01:00
|
|
|
|
|
|
|
// Returns host of a url without a leading 'www.' if present
|
|
|
|
String urlHost(String url) {
|
|
|
|
final host = Uri.parse(url).host;
|
|
|
|
|
|
|
|
if (host.startsWith('www.')) {
|
|
|
|
return host.substring(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return host;
|
|
|
|
}
|