mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-21 12:29:36 +02:00
20 lines
489 B
TypeScript
20 lines
489 B
TypeScript
|
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]
|
||
|
}
|