Comparing version
72
index.js
@@ -10,3 +10,3 @@ /*! | ||
var chars = { '{': '}', '(': ')', '[': ']'}; | ||
var strictCheck = function (str) { | ||
var strictCheck = function(str) { | ||
if (str[0] === '!') { | ||
@@ -16,2 +16,7 @@ return true; | ||
var index = 0; | ||
var pipeIndex = -2; | ||
var closeSquareIndex = -2; | ||
var closeCurlyIndex = -2; | ||
var closeParenIndex = -2; | ||
var backSlashIndex = -2; | ||
while (index < str.length) { | ||
@@ -26,17 +31,22 @@ if (str[index] === '*') { | ||
if (str[index] === '[' && str[index + 1] !== ']') { | ||
var closeIndex = str.indexOf(']', index); | ||
if (closeIndex > index) { | ||
var slashIndex = str.indexOf('\\', index); | ||
if (slashIndex === -1 || slashIndex > closeIndex) { | ||
if (closeSquareIndex !== -1 && str[index] === '[' && str[index + 1] !== ']') { | ||
if (closeSquareIndex < index) { | ||
closeSquareIndex = str.indexOf(']', index); | ||
} | ||
if (closeSquareIndex > index) { | ||
if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) { | ||
return true; | ||
} | ||
backSlashIndex = str.indexOf('\\', index); | ||
if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) { | ||
return true; | ||
} | ||
} | ||
} | ||
if (str[index] === '{' && str[index + 1] !== '}') { | ||
closeIndex = str.indexOf('}', index); | ||
if (closeIndex > index) { | ||
slashIndex = str.indexOf('\\', index); | ||
if (slashIndex === -1 || slashIndex > closeIndex) { | ||
if (closeCurlyIndex !== -1 && str[index] === '{' && str[index + 1] !== '}') { | ||
closeCurlyIndex = str.indexOf('}', index); | ||
if (closeCurlyIndex > index) { | ||
backSlashIndex = str.indexOf('\\', index); | ||
if (backSlashIndex === -1 || backSlashIndex > closeCurlyIndex) { | ||
return true; | ||
@@ -47,7 +57,7 @@ } | ||
if (str[index] === '(' && str[index + 1] === '?' && /[:!=]/.test(str[index + 2]) && str[index + 3] !== ')') { | ||
closeIndex = str.indexOf(')', index); | ||
if (closeIndex > index) { | ||
slashIndex = str.indexOf('\\', index); | ||
if (slashIndex === -1 || slashIndex > closeIndex) { | ||
if (closeParenIndex !== -1 && str[index] === '(' && str[index + 1] === '?' && /[:!=]/.test(str[index + 2]) && str[index + 3] !== ')') { | ||
closeParenIndex = str.indexOf(')', index); | ||
if (closeParenIndex > index) { | ||
backSlashIndex = str.indexOf('\\', index); | ||
if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) { | ||
return true; | ||
@@ -58,10 +68,12 @@ } | ||
if (str[index] === '(' && str[index + 1] !== '|') { | ||
var pipeIndex = str.indexOf('|', index); | ||
if (pipeIndex > index && str[pipeIndex + 1] !== ')') { | ||
closeIndex = str.indexOf(')', pipeIndex); | ||
if (closeIndex > pipeIndex) { | ||
slashIndex = str.indexOf('\\', pipeIndex); | ||
if (slashIndex === -1 || slashIndex > closeIndex) { | ||
return true; | ||
if (pipeIndex !== -1 && str[index] === '(' && str[index + 1] !== '|') { | ||
if (pipeIndex < index) { | ||
pipeIndex = str.indexOf('|', index); | ||
} | ||
if (pipeIndex !== -1 && str[pipeIndex + 1] !== ')') { | ||
closeParenIndex = str.indexOf(')', pipeIndex); | ||
if (closeParenIndex > pipeIndex) { | ||
backSlashIndex = str.indexOf('\\', pipeIndex); | ||
if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) { | ||
return true; | ||
} | ||
@@ -73,3 +85,3 @@ } | ||
if (str[index] === '\\') { | ||
var open = str[index+1]; | ||
var open = str[index + 1]; | ||
index += 2; | ||
@@ -93,5 +105,5 @@ var close = chars[open]; | ||
return false; | ||
} | ||
}; | ||
var relaxedCheck = function (str) { | ||
var relaxedCheck = function(str) { | ||
if (str[0] === '!') { | ||
@@ -107,3 +119,3 @@ return true; | ||
if (str[index] === '\\') { | ||
var open = str[index+1]; | ||
var open = str[index + 1]; | ||
index += 2; | ||
@@ -127,3 +139,3 @@ var close = chars[open]; | ||
return false; | ||
} | ||
}; | ||
@@ -147,2 +159,2 @@ module.exports = function isGlob(str, options) { | ||
return check(str); | ||
} | ||
}; |
{ | ||
"name": "is-glob", | ||
"description": "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience.", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"homepage": "https://github.com/micromatch/is-glob", | ||
@@ -25,3 +25,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha && node benchmark.js" | ||
}, | ||
@@ -28,0 +28,0 @@ "dependencies": { |
@@ -1,2 +0,2 @@ | ||
# is-glob [](https://www.npmjs.com/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://travis-ci.org/micromatch/is-glob) [](https://ci.appveyor.com/project/micromatch/is-glob) | ||
# is-glob [](https://www.npmjs.com/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://github.com/micromatch/is-glob/actions) | ||
@@ -3,0 +3,0 @@ > Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience. |
13609
2.89%132
10%