Rocket.Chat.ReactNative/app/lib/methods/helpers/server.ts

19 lines
381 B
TypeScript

/*
Extract hostname from url
url = 'https://open.rocket.chat/method'
hostname = 'open.rocket.chat'
*/
export const extractHostname = (url: string): string => {
let hostname;
if (url.indexOf('//') > -1) {
[, , hostname] = url.split('/');
} else {
[hostname] = url.split('/');
}
[hostname] = hostname.split(':');
[hostname] = hostname.split('?');
return hostname;
};