import { IAnonymousPaths , IBasePath } from 'src/core/public' ; import { CoreService } from '../../types' ; interface Deps { basePath : IBasePath ; } export class AnonymousPathsService implements CoreService < IAnonymousPaths , IAnonymousPaths > { private readonly paths = new Set < string > ( ) ; public setup ( { basePath } ) { return { isAnonymous : ( path ) : boolean => { const pathWithoutBasePath = basePath . remove ( path ) ; return this . paths . has ( normalizePath ( pathWithoutBasePath ) ) ; } , register : ( path ) => { this . paths . add ( normalizePath ( path ) ) ; } , normalizePath , } ; } public start ( deps ) { return this . setup ( deps ) ; } public stop ( ) { } } const normalizePath = ( path ) => { let normalized = path . toLowerCase ( ) ; if ( normalized . endsWith ( '/' ) ) { normalized = normalized . slice ( 0 , normalized . length - 1 ) ; } if ( ! normalized . startsWith ( '/' ) ) { normalized = `/${ normalized }` ; } return normalized ; } ;