match


RegExp → String → [String | Undefined]

Parameters

  • rxA regular expression.
  • strThe string to match against

Returns Array The list of matches or empty array.

Added in v0.1.0

Tests a regular expression against a String. Note that this function will return an empty array when there are no matches. This differs from String.prototype.match which returns null when there are no matches.

See also test.

  1. R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
  2. R.match(/a/, 'b'); //=> []
  3. R.match(/a/, null); //=> TypeError: null does not have a method named "match"

split


(String | RegExp) → String → [String]

Parameters

  • sepThe pattern.
  • strThe string to separate into an array.

Returns Array The array of strings from str separated by sep.

Added in v0.1.0

Splits a string into an array of strings based on the given separator.

See also join.

  1. const pathComponents = R.split('/');
  2. R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node']
  3. R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']

trim


String → String

Parameters

  • strThe string to trim.

Returns String Trimmed version of str.

Added in v0.6.0

Removes (strips) whitespace from both ends of the string.

  1. R.trim(' xyz '); //=> 'xyz'
  2. R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']

replace


RegExp|String → String → String → String

Parameters

  • patternA regular expression or a substring to match.
  • replacementThe string to replace the matches with.
  • strThe String to do the search and replacement in.

Returns String The result.

Added in v0.7.0

Replace a substring or regex match in a string with a replacement.

The first two parameters correspond to the parameters of the String.prototype.replace() function, so the second parameter can also be a function.

  1. R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
  2. R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'
  3. // Use the "g" (global) flag to replace all occurrences:
  4. R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'

toLower


String → String

Parameters

  • strThe string to lower case.

Returns String The lower case version of str.

Added in v0.9.0

The lower case version of a string.

See also toUpper.

  1. R.toLower('XYZ'); //=> 'xyz'

toUpper


String → String

Parameters

  • strThe string to upper case.

Returns String The upper case version of str.

Added in v0.9.0

The upper case version of a string.

See also toLower.

  1. R.toUpper('abc'); //=> 'ABC'

test


RegExp → String → Boolean

Parameters

  • pattern
  • str

Returns Boolean

Added in v0.12.0

Determines whether a given string matches a given regular expression.

See also match.

  1. R.test(/^x/, 'xyz'); //=> true
  2. R.test(/^y/, 'xyz'); //=> false

toString


* → String

Added in v0.14.0

Returns the string representation of the given value. eval‘ing the output should result in a value equivalent to the input value. Many of the built-in toString methods do not satisfy this requirement.

If the given value is an [object Object] with a toString method other than Object.prototype.toString, this method is invoked with no arguments to produce the return value. This means user-defined constructor functions can provide a suitable toString method. For example:

  1. function Point(x, y) {
  2. this.x = x;
  3. this.y = y;
  4. }
  5. Point.prototype.toString = function() {
  6. return 'new Point(' + this.x + ', ' + this.y + ')';
  7. };
  8. R.toString(new Point(1, 2)); //=> 'new Point(1, 2)'
  9. R.toString(42); //=> '42'
  10. R.toString('abc'); //=> '"abc"'
  11. R.toString([1, 2, 3]); //=> '[1, 2, 3]'
  12. R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}'
  13. R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")'