The first thing I would do is change the name, perhaps to parseLineToHtml, which is more in line with what it does.
The second thing unfortunately depends on context, but the isFirstLine parameter bothers me. Probably because this function is very close to being able to operate on single lines independent of additional context, if not for that parameter.
The third thing is probably shuffle the br condition to be first so we don't have to repeatedly ask if the line isn't empty. Personally, I don't mind small, non-nested if-ladders as they can sometimes be more readable than ternaries.
And finally, I wouldn't do any of that without tests ( :
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The first thing I would do is change the name, perhaps to
parseLineToHtml
, which is more in line with what it does.The second thing unfortunately depends on context, but the
isFirstLine
parameter bothers me. Probably because this function is very close to being able to operate on single lines independent of additional context, if not for that parameter.The third thing is probably shuffle the
br
condition to be first so we don't have to repeatedly ask if the line isn't empty. Personally, I don't mind small, non-nested if-ladders as they can sometimes be more readable than ternaries.And finally, I wouldn't do any of that without tests ( :