mirror of
https://github.com/krawieck/lemmur/
synced 2024-12-15 10:04:13 +01:00
28 lines
598 B
Dart
28 lines
598 B
Dart
/// Strips protocol, 'www.', and trailing '/' from [url] aka. cleans it up
|
|
String cleanUpUrl(String url) {
|
|
var newUrl = url;
|
|
|
|
if (newUrl.startsWith('https://')) {
|
|
newUrl = newUrl.substring(8);
|
|
}
|
|
if (newUrl.startsWith('www.')) {
|
|
newUrl = newUrl.substring(4);
|
|
}
|
|
if (newUrl.endsWith('/')) {
|
|
newUrl = newUrl.substring(0, newUrl.length - 1);
|
|
}
|
|
|
|
return newUrl;
|
|
}
|
|
|
|
// 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;
|
|
}
|