From 8dfc6ddbd086c6fe47b70e893b18d9ce9920dc4c Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Sat, 7 Feb 2015 16:30:11 -0500 Subject: [PATCH] adds `is-glob` to detect globs --- index.js | 13 ++++++++----- test.js | 9 +++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index a5266f9..1db2241 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ 'use strict'; var pathRe = require('glob-path-regex'); +var isGlob = require('is-glob'); /** * Parse a glob pattern into sections @@ -22,8 +23,10 @@ var pathRe = require('glob-path-regex'); */ module.exports = function parseGlob(pattern) { + // leave `pattern` unmodified var glob = pattern; var tok = {}; + tok.isGlob = isGlob(pattern); var braces = pattern.indexOf('{') !== -1; if (braces) { @@ -67,11 +70,11 @@ module.exports = function parseGlob(pattern) { tok.ext = tok.extname.split('.').slice(-1)[0]; if (braces) { - tok.dirname = unescape(tok.dirname); - tok.filename = unescape(tok.filename); - tok.basename = unescape(tok.basename); - tok.extname = unescape(tok.extname); - tok.ext = unescape(tok.ext); + tok.dirname = tok.dirname ? unescape(tok.dirname) : ''; + tok.filename = tok.filename ? unescape(tok.filename) : ''; + tok.basename = tok.basename ? unescape(tok.basename) : ''; + tok.extname = tok.extname ? unescape(tok.extname) : ''; + tok.ext = tok.ext ? unescape(tok.ext) : ''; } tok.dotfiles = tok.filename.charAt(0) === '.'; diff --git a/test.js b/test.js index e692072..f30f5be 100644 --- a/test.js +++ b/test.js @@ -10,6 +10,15 @@ var assert = require('assert'); var parse = require('./'); +it('should detect when the pattern is a glob pattern:', function () { + assert.equal(parse('a.min.js').isGlob, false); + assert.equal(parse('*.min.js').isGlob, true); + assert.equal(parse('foo/{a,b}.min.js').isGlob, true); + assert.equal(parse('foo/(a|b).min.js').isGlob, true); + assert.equal(parse('foo/[a-b].min.js').isGlob, true); + assert.equal(parse('!foo').isGlob, true); +}); + 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/');