import { getDirectoryContents } from '.' ; import { Contents } from '../shared/fileDirectory' ; const searchForOptions = ( term , currentDirectoryContents ) : string [ ] => { const o = Object . values ( currentDirectoryContents ) . filter ( ( x ) => x . searchText . filter ( ( x ) => x . startsWith ( term ) ) . length > 0 ) . map ( ( x ) => x . display ) ; return o ; } ; const autocomplete = ( path = '' , currentDirectoryContents ) : string [ ] => { const parts = path . split ( '/' ) ; const pathToGrep = parts . slice ( 0 , parts . length - 1 ) ; const contents = getDirectoryContents ( pathToGrep , currentDirectoryContents ) ; if ( contents ) { const options = searchForOptions ( parts [ parts . length - 1 ] , contents ) ; return options ; } return [ ] ; } ; export default autocomplete ;