1 |
3a515b92
|
cagy
|
/*!
|
2 |
|
|
* is-glob <https://github.com/jonschlinkert/is-glob>
|
3 |
|
|
*
|
4 |
|
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
5 |
|
|
* Released under the MIT License.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
var isExtglob = require('is-extglob');
|
9 |
|
|
var chars = { '{': '}', '(': ')', '[': ']'};
|
10 |
|
|
var strictRegex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
|
11 |
|
|
var relaxedRegex = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
|
12 |
|
|
|
13 |
|
|
module.exports = function isGlob(str, options) {
|
14 |
|
|
if (typeof str !== 'string' || str === '') {
|
15 |
|
|
return false;
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
if (isExtglob(str)) {
|
19 |
|
|
return true;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
var regex = strictRegex;
|
23 |
|
|
var match;
|
24 |
|
|
|
25 |
|
|
// optionally relax regex
|
26 |
|
|
if (options && options.strict === false) {
|
27 |
|
|
regex = relaxedRegex;
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
while ((match = regex.exec(str))) {
|
31 |
|
|
if (match[2]) return true;
|
32 |
|
|
var idx = match.index + match[0].length;
|
33 |
|
|
|
34 |
|
|
// if an open bracket/brace/paren is escaped,
|
35 |
|
|
// set the index to the next closing character
|
36 |
|
|
var open = match[1];
|
37 |
|
|
var close = open ? chars[open] : null;
|
38 |
|
|
if (open && close) {
|
39 |
|
|
var n = str.indexOf(close, idx);
|
40 |
|
|
if (n !== -1) {
|
41 |
|
|
idx = n + 1;
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
str = str.slice(idx);
|
46 |
|
|
}
|
47 |
|
|
return false;
|
48 |
|
|
};
|