diff --git a/index.js b/index.js index 1db2241..462db22 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,10 @@ module.exports = function parseGlob(pattern) { // leave `pattern` unmodified var glob = pattern; var tok = {}; + + tok.pattern = pattern; tok.isGlob = isGlob(pattern); + tok.isNegated = pattern.charAt(0) === '!'; var braces = pattern.indexOf('{') !== -1; if (braces) { @@ -34,7 +37,6 @@ module.exports = function parseGlob(pattern) { } if (!/(\/|\*\*)/.test(glob)) { - tok.pattern = pattern; tok.dirname = ''; tok.filename = pattern; @@ -49,9 +51,7 @@ module.exports = function parseGlob(pattern) { } else { var m = pathRe().exec(glob) || []; - tok.pattern = pattern; tok.dirname = m[1]; - tok.filename = glob.substr(tok.dirname.length); var dot = tok.filename.indexOf('.', 1); if (dot !== -1) { diff --git a/test.js b/test.js index f30f5be..48bc46a 100644 --- a/test.js +++ b/test.js @@ -19,6 +19,15 @@ it('should detect when the pattern is a glob pattern:', function () { assert.equal(parse('!foo').isGlob, true); }); +it('should detect when a pattern is negated:', function () { + assert.equal(parse('a.min.js').isNegated, false); + assert.equal(parse('!*.min.js').isNegated, true); + assert.equal(parse('!foo/{a,b}.min.js').isNegated, true); + assert.equal(parse('!foo/(a|b).min.js').isNegated, true); + assert.equal(parse('!foo/[a-b].min.js').isNegated, true); + assert.equal(parse('foo').isNegated, false); +}); + it('should get a filename from a complex pattern:', function () { assert.equal(parse('*.min.js').dirname, ''); assert.equal(parse('/a/b/c').dirname, '/a/b/');