main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry1 from "./internal/_curry1.js";
|
---|
| 2 | var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\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 |
|
---|
| 21 | var trim = !hasProtoTrim ||
|
---|
| 22 | /*#__PURE__*/
|
---|
| 23 | ws.trim() || !
|
---|
| 24 | /*#__PURE__*/
|
---|
| 25 | zeroWidth.trim() ?
|
---|
| 26 | /*#__PURE__*/
|
---|
| 27 | _curry1(function trim(str) {
|
---|
| 28 | var beginRx = new RegExp('^[' + ws + '][' + ws + ']*');
|
---|
| 29 | var endRx = new RegExp('[' + ws + '][' + ws + ']*$');
|
---|
| 30 | return str.replace(beginRx, '').replace(endRx, '');
|
---|
| 31 | }) :
|
---|
| 32 | /*#__PURE__*/
|
---|
| 33 | _curry1(function trim(str) {
|
---|
| 34 | return str.trim();
|
---|
| 35 | });
|
---|
| 36 | export default trim; |
---|
Note:
See
TracBrowser
for help on using the repository browser.