1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-23 05:19:37 +02:00

Added url parser to support wider range of addresses

This commit is contained in:
unknown 2021-06-11 15:33:06 +02:00
parent 5968663be4
commit a5504e6e80
7 changed files with 63 additions and 24 deletions

View file

@ -0,0 +1,20 @@
export const urlParser = (url: string): string[] => {
let parsedUrl: string;
let displayUrl: string;
if (/https?:\/\//.test(url)) {
// Url starts with http[s]:// -> leave it as it is
parsedUrl = url;
} else {
// No protocol -> apply http:// prefix
parsedUrl = `http://${url}`;
}
// Create simplified url to display as text
displayUrl = url
.replace(/https?:\/\//, '')
.replace('www.', '')
.replace(/\/$/, '');
return [displayUrl, parsedUrl]
}