trim whitespace on buffer leave for javascript