Enhancement to the trim method

Enhancement to the trim method


Hi all,
I've submitted Ticket #4848 (new enhancement) about a week ago and
would like to hear what you guys think. I think it's handy for
telephone numbers, bank accounts (IBAN/SWIFT) ect. I realize that
changing the core API (no regression) requires some merit. Am I the
only one who like this idea?
/**
* Uses a regular expression to remove whitespace from the given
string.
* @param {String} text The string to trim.
* @param {Boolean} [all] True to remove all white-space from the
text.
* @return {String}
*/
trim: function(text, all) {
var reg = all===true ? /\s+/g : /^\s+|\s+$/g;
return (text || "").replace(reg, '');
}
Cheers, Jon.
PS. noticed a post back in november 2008 about optimizing the trim
method but don't know what the conclusion was.