/**
 * captures 4 components of a URI: scheme, hierarchical part, query and
 * fragement.
 */ const URI_REGEX = /^(?:([^:/?#]+):)((?:\/\/)?[^?#]*)(?:\\?([^#]*))?(?:#([^?]*))?$/ ; export interface Uri { scheme : string ; hierPart : string ; query ? : string ; fragment ? : string ; } export function parseUri ( value ) { let match = URI_REGEX . exec ( value ) ; if ( ! match ) { return null ; } let result = { scheme : match [ 1 ] , hierPart : match [ 2 ] } ; if ( match [ 3 ] ) { result . query = match [ 3 ] ; } if ( match [ 4 ] ) { result . fragment = match [ 4 ] ; } return result ; } export function isHierarchical ( uri ) { return uri . hierPart . startsWith ( '//' ) ; } export function getPath ( uri ) { let pathSearchStart = ( uri . hierPart . startsWith ( '//' ) ) ? 2 : 0 ; let pathIndex = uri . hierPart . indexOf ( '/' , pathSearchStart ) ; if ( pathIndex < 0 ) { return null ; } return uri . hierPart . substring ( pathIndex ) ; }