I wonder if trim12 might be improved by avoiding calling slice if there
is no trailing white space:
function trim12 (str) {
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length,
len = i;
while (ws.test(str.charAt(--i)));
return i + 1 < len ? str.slice(0, i + 1) : str;
}
Also, you did not say it explicitly, but are you saying that /\s/.test()
is faster than whitespace.indexOf() ?
- Ken