2 * is-glob <https://github.com/jonschlinkert/is-glob>
4 * Copyright (c) 2014-2017, Jon Schlinkert.
5 * Released under the MIT License.
8 var isExtglob = require('is-extglob');
9 var chars = { '{': '}', '(': ')', '[': ']'};
10 var strictCheck = function(str) {
16 var closeSquareIndex = -2;
17 var closeCurlyIndex = -2;
18 var closeParenIndex = -2;
19 var backSlashIndex = -2;
20 while (index < str.length) {
21 if (str[index] === '*') {
25 if (str[index + 1] === '?' && /[\].+)]/.test(str[index])) {
29 if (closeSquareIndex !== -1 && str[index] === '[' && str[index + 1] !== ']') {
30 if (closeSquareIndex < index) {
31 closeSquareIndex = str.indexOf(']', index);
33 if (closeSquareIndex > index) {
34 if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
37 backSlashIndex = str.indexOf('\\', index);
38 if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
44 if (closeCurlyIndex !== -1 && str[index] === '{' && str[index + 1] !== '}') {
45 closeCurlyIndex = str.indexOf('}', index);
46 if (closeCurlyIndex > index) {
47 backSlashIndex = str.indexOf('\\', index);
48 if (backSlashIndex === -1 || backSlashIndex > closeCurlyIndex) {
54 if (closeParenIndex !== -1 && str[index] === '(' && str[index + 1] === '?' && /[:!=]/.test(str[index + 2]) && str[index + 3] !== ')') {
55 closeParenIndex = str.indexOf(')', index);
56 if (closeParenIndex > index) {
57 backSlashIndex = str.indexOf('\\', index);
58 if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
64 if (pipeIndex !== -1 && str[index] === '(' && str[index + 1] !== '|') {
65 if (pipeIndex < index) {
66 pipeIndex = str.indexOf('|', index);
68 if (pipeIndex !== -1 && str[pipeIndex + 1] !== ')') {
69 closeParenIndex = str.indexOf(')', pipeIndex);
70 if (closeParenIndex > pipeIndex) {
71 backSlashIndex = str.indexOf('\\', pipeIndex);
72 if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
79 if (str[index] === '\\') {
80 var open = str[index + 1];
82 var close = chars[open];
85 var n = str.indexOf(close, index);
91 if (str[index] === '!') {
101 var relaxedCheck = function(str) {
102 if (str[0] === '!') {
106 while (index < str.length) {
107 if (/[*?{}()[\]]/.test(str[index])) {
111 if (str[index] === '\\') {
112 var open = str[index + 1];
114 var close = chars[open];
117 var n = str.indexOf(close, index);
123 if (str[index] === '!') {
133 module.exports = function isGlob(str, options) {
134 if (typeof str !== 'string' || str === '') {
138 if (isExtglob(str)) {
142 var check = strictCheck;
144 // optionally relax check
145 if (options && options.strict === false) {
146 check = relaxedCheck;