mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
Add support for all protocols for urls (#74)
This commit is contained in:
parent
8808f65b47
commit
45fb337c87
1 changed files with 16 additions and 17 deletions
|
@ -1,24 +1,23 @@
|
||||||
export const urlParser = (url: string): string[] => {
|
const hasProtocol = (url: string): boolean => /^\w+:\/\//.test(url);
|
||||||
let parsedUrl: string;
|
const isSteamUrl = (url: string): boolean => /^steam:\/\//.test(url);
|
||||||
let displayUrl: string;
|
const isWebUrl = (url: string): boolean => /^https?:\/\//.test(url);
|
||||||
|
|
||||||
if (/(https?|steam):\/\//.test(url)) {
|
export const urlParser = (url: string): string[] => {
|
||||||
// Url starts with http[s]:// or steam:// -> leave it as it is
|
if (!hasProtocol(url)) {
|
||||||
parsedUrl = url;
|
|
||||||
} else {
|
|
||||||
// No protocol -> apply http:// prefix
|
// No protocol -> apply http:// prefix
|
||||||
parsedUrl = `http://${url}`;
|
url = `http://${url}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create simplified url to display as text
|
// Create simplified url to display as text
|
||||||
if (/steam:\/\//.test(url)) {
|
let displayUrl: string;
|
||||||
|
if (isSteamUrl(url)) {
|
||||||
displayUrl = 'Run Steam App';
|
displayUrl = 'Run Steam App';
|
||||||
} else {
|
} else if (isWebUrl(url)) {
|
||||||
displayUrl = url
|
displayUrl = url
|
||||||
.replace(/https?:\/\//, '')
|
.replace(/https?:\/\//, '')
|
||||||
.replace('www.', '')
|
.replace('www.', '')
|
||||||
.replace(/\/$/, '');
|
.replace(/\/$/, '');
|
||||||
}
|
} else displayUrl = url;
|
||||||
|
|
||||||
return [displayUrl, parsedUrl]
|
return [displayUrl, url];
|
||||||
}
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue