import { Dictionary } from "./utils/dictionary" ; param lineOutput param columnSeparator return export function parseLineOutput ( lineOutput , columnSeparator ) { const headers = lineOutput . shift ( ) ; if ( ! headers ) { return [ ] ; } const posHeaders = findPositionHeaders ( headers , columnSeparator ) ; const parsedHeaders = headers . toLowerCase ( ) . replace ( columnSeparator , '|' ) . split ( '|' ) ; return lineOutput . map ( ( line ) => { const lineInfoObject = Dictionary . of < string > ( ) ; const bits = extractBits ( line , posHeaders ) ; bits . forEach ( ( columnValue , index ) => { lineInfoObject [ parsedHeaders [ index ] . trim ( ) ] = columnValue . trim ( ) ; } ) ; return lineInfoObject ; } ) ; } function findPositionHeaders ( headers , columnSeparator ) { const posHeaders = [ ] ; const parsedHeaders = headers . replace ( columnSeparator , '|' ) . split ( '|' ) ; let takenTo = 0 ; parsedHeaders . forEach ( ( header ) => { const headerPos = headers . indexOf ( header , takenTo ) ; takenTo = headerPos + header . length ; posHeaders . push ( headerPos ) ; } ) ; return posHeaders ; } function extractBits ( value , positions ) { const bits = [ ] ; let cont = 0 ; while ( positions . length > ++ cont ) { bits . push ( value . substring ( positions [ cont - 1 ] , positions [ cont ] ) ) ; } bits . push ( value . substring ( positions [ cont - 1 ] ) ) ; return bits ; }