Created helper function to replace the authority on a URL

This commit is contained in:
Alejandro Celaya
2021-12-26 13:21:09 +01:00
parent 4f90d147a4
commit ace29ca4a4
2 changed files with 20 additions and 0 deletions

7
src/utils/helpers/uri.ts Normal file
View File

@@ -0,0 +1,7 @@
export const replaceAuthorityFromUri = (uri: string, newAuthority: string): string => {
const [ schema, rest ] = uri.split('://');
const [ , ...pathParts ] = rest.split('/');
const normalizedPath = pathParts.length ? `/${pathParts.join('/')}` : '';
return `${schema}://${newAuthority}${normalizedPath}`;
};