You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

4 years ago
  1. import _curry1 from "./internal/_curry1.js";
  2. var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' + '\u2029\uFEFF';
  3. var zeroWidth = '\u200b';
  4. var hasProtoTrim = typeof String.prototype.trim === 'function';
  5. /**
  6. * Removes (strips) whitespace from both ends of the string.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.6.0
  11. * @category String
  12. * @sig String -> String
  13. * @param {String} str The string to trim.
  14. * @return {String} Trimmed version of `str`.
  15. * @example
  16. *
  17. * R.trim(' xyz '); //=> 'xyz'
  18. * R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']
  19. */
  20. var trim = !hasProtoTrim ||
  21. /*#__PURE__*/
  22. ws.trim() || !
  23. /*#__PURE__*/
  24. zeroWidth.trim() ?
  25. /*#__PURE__*/
  26. _curry1(function trim(str) {
  27. var beginRx = new RegExp('^[' + ws + '][' + ws + ']*');
  28. var endRx = new RegExp('[' + ws + '][' + ws + ']*$');
  29. return str.replace(beginRx, '').replace(endRx, '');
  30. }) :
  31. /*#__PURE__*/
  32. _curry1(function trim(str) {
  33. return str.trim();
  34. });
  35. export default trim;