mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/match.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
|
|
|
|
/**
|
|
* 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`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
|
|
* which returns `null` when there are no matches.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.1.0
|
|
* @category String
|
|
* @sig RegExp -> String -> [String | Undefined]
|
|
* @param {RegExp} rx A regular expression.
|
|
* @param {String} str The string to match against
|
|
* @return {Array} The list of matches or empty array.
|
|
* @see R.test
|
|
* @example
|
|
*
|
|
* R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
|
|
* R.match(/a/, 'b'); //=> []
|
|
* R.match(/a/, null); //=> TypeError: null does not have a method named "match"
|
|
*/
|
|
var match = _curry2(function match(rx, str) {
|
|
return str.match(rx) || [];
|
|
});
|
|
export default match;
|