You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
4 years ago
|
/*!
|
||
|
* is-glob <https://github.com/jonschlinkert/is-glob>
|
||
|
*
|
||
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
|
||
|
var isExtglob = require('is-extglob');
|
||
|
var chars = { '{': '}', '(': ')', '[': ']'};
|
||
|
var strictRegex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
|
||
|
var relaxedRegex = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
|
||
|
|
||
|
module.exports = function isGlob(str, options) {
|
||
|
if (typeof str !== 'string' || str === '') {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (isExtglob(str)) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
var regex = strictRegex;
|
||
|
var match;
|
||
|
|
||
|
// optionally relax regex
|
||
|
if (options && options.strict === false) {
|
||
|
regex = relaxedRegex;
|
||
|
}
|
||
|
|
||
|
while ((match = regex.exec(str))) {
|
||
|
if (match[2]) return true;
|
||
|
var idx = match.index + match[0].length;
|
||
|
|
||
|
// if an open bracket/brace/paren is escaped,
|
||
|
// set the index to the next closing character
|
||
|
var open = match[1];
|
||
|
var close = open ? chars[open] : null;
|
||
|
if (open && close) {
|
||
|
var n = str.indexOf(close, idx);
|
||
|
if (n !== -1) {
|
||
|
idx = n + 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
str = str.slice(idx);
|
||
|
}
|
||
|
return false;
|
||
|
};
|