index.js 467 B

12345678910111213141516171819202122
  1. exports = module.exports = trim;
  2. function trim(str){
  3. if (str.trim) return str.trim();
  4. return exports.right(exports.left(str));
  5. }
  6. exports.left = function(str){
  7. if (str.trimLeft) return str.trimLeft();
  8. return str.replace(/^\s\s*/, '');
  9. };
  10. exports.right = function(str){
  11. if (str.trimRight) return str.trimRight();
  12. var whitespace_pattern = /\s/,
  13. i = str.length;
  14. while (whitespace_pattern.test(str.charAt(--i)));
  15. return str.slice(0, i + 1);
  16. };