import { modifyUrl } from '@osd/std' ; export class BasePath { constructor ( private readonly basePath = '' , public readonly serverBasePath = basePath ) { } public get = ( ) => { return this . basePath ; } ; public prepend = ( path ) : string => { if ( ! this . basePath ) return path ; return modifyUrl ( path , ( parts ) => { if ( ! parts . hostname && parts . pathname && parts . pathname . startsWith ( '/' ) ) { parts . pathname = `${ this . basePath }${ parts . pathname }` ; } } ) ; } ; public remove = ( path ) : string => { if ( ! this . basePath ) { return path ; } if ( path === this . basePath ) { return '/' ; } if ( path . startsWith ( `${ this . basePath }/` ) ) { return path . slice ( this . basePath . length ) ; } return path ; } ; }