/** * Strips all leading and ending whitespaces. * @returns the trimmed string. */ function trim() { var str = this.replace(/^\s+/, ""); var ws = /\s/; var i = str.length; while (ws.test(str.charAt(--i))); return str.slice(0, i + 1); } /** * Checks whether a string is empty or not. * The string is trimmed before checking if the length is 0. * @return true if the trimmed string has a length of 0. */ function isEmpty() { var testString = this.trim(); return 0 == testString.length; } String.prototype.trim = trim; String.prototype.isEmpty = isEmpty;