export function cleanDocString ( rawString ) { return cleanAndSplitDocString ( rawString ) . join ( '\n' ) ; } export function cleanAndSplitDocString ( rawString ) { const unescaped = rawString . replace ( /\r/g , '' ) . replace ( /\t/g , '        ' ) ; const lines = unescaped . split ( '\n' ) ; let leftSpacesToRemove = Number . MAX_VALUE ; lines . forEach ( ( line , index ) => { if ( lines . length <= 1 || index > 0 ) { const trimmed = line . trimLeft ( ) ; if ( trimmed ) { leftSpacesToRemove = Math . min ( leftSpacesToRemove , line . length - trimmed . length ) ; } } } ) ; if ( leftSpacesToRemove >= Number . MAX_VALUE ) { leftSpacesToRemove = 0 ; } const trimmedLines = [ ] ; lines . forEach ( ( line , index ) => { if ( index === 0 ) { trimmedLines . push ( line . trim ( ) ) ; } else { trimmedLines . push ( line . substr ( leftSpacesToRemove ) . trimRight ( ) ) ; } } ) ; while ( trimmedLines . length > 0 && trimmedLines [ 0 ] . length === 0 ) { trimmedLines . shift ( ) ; } while ( trimmedLines . length > 0 && trimmedLines [ trimmedLines . length - 1 ] . length === 0 ) { trimmedLines . pop ( ) ; } return trimmedLines ; } export function extractParameterDocumentation ( functionDocString , paramName ) { if ( ! functionDocString || ! paramName ) { return undefined ; } const docStringLines = cleanAndSplitDocString ( functionDocString ) ; for ( const line of docStringLines ) { const trimmedLine = line . trim ( ) ; let paramOffset = trimmedLine . indexOf ( '@param ' + paramName ) ; if ( paramOffset >= 0 ) { return trimmedLine . substr ( paramOffset + 7 ) ; } paramOffset = trimmedLine . indexOf ( ':param ' + paramName ) ; if ( paramOffset >= 0 ) { return trimmedLine . substr ( paramOffset + 7 ) ; } paramOffset = trimmedLine . indexOf ( paramName + ': ' ) ; if ( paramOffset >= 0 ) { return trimmedLine . substr ( paramOffset ) ; } paramOffset = trimmedLine . indexOf ( paramName + ' (' ) ; if ( paramOffset >= 0 ) { return trimmedLine . substr ( paramOffset ) ; } } return undefined ; }