function trim(str) {
  return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
}
Trim excess whitespace off the beginning and end of a string

@param {String} str The String to trim
@returns {String} The String freed of excess whitespace