mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-10 06:23:11 +08:00
Added url parser to support wider range of addresses
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Parse Material Desgin icon name to be used with mdi/js
|
||||
* @param mdiName Dash separated icon name from MDI, e.g. alert-box-outline
|
||||
* @returns Parsed icon name to be used with mdi/js, e.g mdiAlertBoxOutline
|
||||
*/
|
||||
export const iconParser = (mdiName: string): string => {
|
||||
let parsedName = mdiName
|
||||
.split('-')
|
||||
|
||||
2
client/src/utility/index.ts
Normal file
2
client/src/utility/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './iconParser';
|
||||
export * from './urlParser';
|
||||
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]
|
||||
}
|
||||
Reference in New Issue
Block a user