diff --git a/.verb.md b/.verb.md index 0d57a6b..ad725c6 100644 --- a/.verb.md +++ b/.verb.md @@ -33,7 +33,7 @@ parseGlob('a/b/{c,d}/*.js'); basename: '*', extname: '.js', ext: 'js' }, - is: { glob: true, negated: false, globstar: false, + is: { glob: true, braces: true, negated: false, globstar: false, dotfile: false, dotdir: false }, original: 'a/b/{c,d}/*.js', pattern: 'a/b/{c,d}/*.js' } diff --git a/README.md b/README.md index f8141cf..ea18e5d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ parseGlob('a/b/{c,d}/*.js'); basename: '*', extname: '.js', ext: 'js' }, - is: { glob: true, negated: false, globstar: false, + is: { glob: true, braces: true, negated: false, globstar: false, dotfile: false, dotdir: false }, original: 'a/b/{c,d}/*.js', pattern: 'a/b/{c,d}/*.js' } diff --git a/index.js b/index.js index 00388f8..35c8ee8 100644 --- a/index.js +++ b/index.js @@ -40,22 +40,17 @@ function parseGlob(pattern, getbase) { tok.pattern = pattern; path.whole = tok.pattern; - // is the pattern actually a glob? - tok.is.glob = isGlob(glob); + // Boolean values + tok.is.glob = isGlob(glob); + tok.is.negated = glob.charAt(0) === '!'; + tok.is.globstar = glob.indexOf('**') !== -1; - // is it a negation pattern? - tok.is.negated = glob.charAt(0) === '!'; - - // does the pattern contain braces? var braces = glob.indexOf('{') !== -1; if (tok.is.glob && braces) { tok.is.braces = true; glob = glob.substr(0, braces) + escape(glob.substr(braces)); } - // does the pattern contain a globstar (`**`)? - tok.is.globstar = glob.indexOf('**') !== -1; - // if there is no `/` and no `**`, this means our // pattern can only match file names if (glob.indexOf('/') === -1 && !tok.is.globstar) { @@ -65,13 +60,17 @@ function parseGlob(pattern, getbase) { var basename = /^([^.]*)/.exec(glob); if (basename) { - path.basename = basename[0] ? unescape(basename[0]) : ''; + path.basename = basename[0] || ''; path.extname = glob.substr(path.basename.length); } else { path.basename = tok.original; path.extname = ''; } + path.ext = path.extname.split('.').slice(-1)[0]; + if (braces) { + path.basename = unescape(path.basename); + } // we either have a `/` or `**` } else { @@ -116,7 +115,6 @@ function parseGlob(pattern, getbase) { tok.pattern = tok.path.filename; } } - return tok; } diff --git a/test.js b/test.js index afa0bbd..b52177b 100644 --- a/test.js +++ b/test.js @@ -14,9 +14,6 @@ function getBase(glob) { return parse(glob, true); } -console.log(parse('a/b/d/e')) - - describe('`is` object:', function () { it('should detect when the pattern is a glob pattern:', function () { assert.equal(parse('a.min.js').is.glob, false);