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:
parent
5968663be4
commit
a5504e6e80
7 changed files with 63 additions and 24 deletions
20
client/src/utility/urlParser.ts
Normal file
20
client/src/utility/urlParser.ts
Normal 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]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue