@duboisp Definitely use <code>trim()</code> rather than <code>.replace(/\s\s+/g, ' ').replace(/^\s+|\s+$/g, '')</code>. I benchmarked it and using <code>trim()</code> decreases execution time by 79%.

My test ran both approaches 200,000 times on the following string <code>'			 test				 '</code>. The replace approach took an average of 159 ms while the trim approach took an average of 33 ms (so ((33 - 159)/159)*100% = -79%).