import { Location , Path } from '@motorcycle/history' ; export function isStrictlyInScope ( namespace ) { return function ( location ) : boolean { const pathParts = splitPath ( location . path ) ; return namespace . every ( ( v , i ) => pathParts [ i ] === v ) ; } ; } export function getFilteredPath ( namespace , path ) { return '/' + filterPath ( splitPath ( path ) , namespace ) ; } export function getUnfilteredPath ( namespace , path ) { return path . replace ( getFilteredPath ( namespace , path ) , '' ) ; } export function newLocation ( location , pathname ) { const l = { } ; const keys = Object . keys ( location ) as Array < keyof Location > ; for ( let i = 0 ; i < keys . length ; ++ i ) { l [ keys [ i ] ] = location [ keys [ i ] ] ; } l . pathname = pathname ; return l ; } export function splitPath ( path ) { return path . split ( '/' ) . filter ( ( p ) => p . length > 0 ) ; } export function filterPath ( pathParts , namespace ) { return pathParts . filter ( ( part ) => namespace . indexOf ( part ) < 0 ) . join ( '/' ) ; } export function pathJoin ( parts ) { const replace = new RegExp ( '/{1,}' , 'g' ) ; return parts . join ( '/' ) . replace ( replace , '/' ) ; }