In most programming languages, there exist certain simple and useful functions that people come to rely upon. From my days with Perl, chomp was one of those functions for me.
Given a string, chomp bit off all newline characters at the end of the string (and returned the number of newline characters it removed).
return raw_text.replace(/(\n|\r)+$/, '');
Another step here would be to extend the String object, add this as a method to the prototype, which I may tackle next time.