aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nanomatch/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/nanomatch/index.js')
-rw-r--r--node_modules/nanomatch/index.js71
1 files changed, 55 insertions, 16 deletions
diff --git a/node_modules/nanomatch/index.js b/node_modules/nanomatch/index.js
index 3ffd08727..f402d59c9 100644
--- a/node_modules/nanomatch/index.js
+++ b/node_modules/nanomatch/index.js
@@ -169,7 +169,7 @@ nanomatch.isMatch = function(str, pattern, options) {
throw new TypeError('expected a string: "' + util.inspect(str) + '"');
}
- if (isEmptyString(str) || isEmptyString(pattern)) {
+ if (utils.isEmptyString(str) || utils.isEmptyString(pattern)) {
return false;
}
@@ -279,7 +279,7 @@ nanomatch.any = function(str, patterns, options) {
throw new TypeError('expected a string: "' + util.inspect(str) + '"');
}
- if (isEmptyString(str) || isEmptyString(patterns)) {
+ if (utils.isEmptyString(str) || utils.isEmptyString(patterns)) {
return false;
}
@@ -397,7 +397,7 @@ nanomatch.contains = function(str, patterns, options) {
}
if (typeof patterns === 'string') {
- if (isEmptyString(str) || isEmptyString(patterns)) {
+ if (utils.isEmptyString(str) || utils.isEmptyString(patterns)) {
return false;
}
@@ -477,10 +477,10 @@ nanomatch.matchKeys = function(obj, patterns, options) {
*/
nanomatch.matcher = function matcher(pattern, options) {
- if (isEmptyString(pattern)) {
+ if (utils.isEmptyString(pattern)) {
return function() {
return false;
- }
+ };
}
if (Array.isArray(pattern)) {
@@ -530,11 +530,54 @@ nanomatch.matcher = function matcher(pattern, options) {
}
var fn = test(re);
- fn.result = re.result;
+ Object.defineProperty(fn, 'result', {
+ configurable: true,
+ enumerable: false,
+ value: re.result
+ });
return fn;
};
/**
+ * Returns an array of matches captured by `pattern` in `string, or
+ * `null` if the pattern did not match.
+ *
+ * ```js
+ * var nm = require('nanomatch');
+ * nm.capture(pattern, string[, options]);
+ *
+ * console.log(nm.capture('test/*.js', 'test/foo.js'));
+ * //=> ['foo']
+ * console.log(nm.capture('test/*.js', 'foo/bar.css'));
+ * //=> null
+ * ```
+ * @param {String} `pattern` Glob pattern to use for matching.
+ * @param {String} `string` String to match
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
+ * @return {Boolean} Returns an array of captures if the string matches the glob pattern, otherwise `null`.
+ * @api public
+ */
+
+nanomatch.capture = function(pattern, str, options) {
+ var re = nanomatch.makeRe(pattern, extend({capture: true}, options));
+ var unixify = utils.unixify(options);
+
+ function match() {
+ return function(string) {
+ var match = re.exec(unixify(string));
+ if (!match) {
+ return null;
+ }
+
+ return match.slice(1);
+ };
+ }
+
+ var capture = memoize('capture', pattern, options, match);
+ return capture(str);
+};
+
+/**
* Create a regular expression from the given glob `pattern`.
*
* ```js
@@ -564,10 +607,14 @@ nanomatch.makeRe = function(pattern, options) {
}
function makeRe() {
- var res = nanomatch.create(pattern, options);
var opts = utils.extend({wrap: false}, options);
+ var res = nanomatch.create(pattern, opts);
var regex = toRegex(res.output, opts);
- regex.result = res;
+ Object.defineProperty(regex, 'result', {
+ configurable: true,
+ enumerable: false,
+ value: res
+ });
return regex;
}
@@ -728,14 +775,6 @@ nanomatch.clearCache = function() {
};
/**
- * Returns true if the given value is effectively an empty string
- */
-
-function isEmptyString(val) {
- return String(val) === '' || String(val) === './';
-}
-
-/**
* Compose a matcher function with the given patterns.
* This allows matcher functions to be compiled once and
* called multiple times.