import { locatorRE } from '../util/regex' ; import { en } from '../data/en' ; import { de } from '../data/de' ; import { fr } from '../data/fr' ; const localeMappings = [ en , de , fr ] ; interface interface LocatorResult { label : string ; natural : string ; } interface interface FullSuffix { locator : string ; label : string ; suffix : string ; } export param { string } locatorString returns { LocatorResult } function retrieveLocator ( locatorString ) { for ( let locale of localeMappings ) { for ( let loc of Object . keys ( locale ) ) { if ( locatorString . indexOf ( loc ) === 0 ) { return { label : locale [ loc ] , natural : loc } ; } } } return { label : '' , natural : '' } ; } param { string } afterKey returns { FullSuffix } export function extractLocator ( afterKey ) { let retObject = { locator : '' , label : 'page' , suffix : '' } ; afterKey = afterKey . trim ( ) ; if ( afterKey [ 0 ] === ',' ) afterKey = afterKey . substr ( 1 ) . trim ( ) ; if ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 ] . includes ( parseInt ( afterKey [ 0 ] ) ) ) { let locator = /^\d+(-\d+)?/ . exec ( afterKey ) ; if ( locator ) { retObject . locator = locator [ 0 ] ; retObject . suffix = afterKey . replace ( locator [ 0 ] , '' ) ; } return retObject ; } let result = retrieveLocator ( afterKey ) ; if ( result . label === '' ) { retObject . suffix = afterKey ; return retObject ; } retObject . label = result . label ; afterKey = afterKey . substr ( result . natural . length ) . trim ( ) ; let match ; let splitIndex = 0 ; while ( ( match = locatorRE . exec ( afterKey ) ) !== null ) { splitIndex = match . index + match [ 0 ] . length ; } retObject . locator = afterKey . substr ( 0 , splitIndex ) . trim ( ) ; retObject . suffix = afterKey . substr ( splitIndex + 1 ) . trim ( ) ; return retObject ; }