adds isNegated property

This commit is contained in:
jonschlinkert 2015-02-07 16:54:16 -05:00
parent 8704e60f3e
commit 0e3768bbab
2 changed files with 12 additions and 3 deletions

View File

@ -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) {

View File

@ -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/');