Skip to content

Commit

Permalink
expose .hasMagic() (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieter Luypaert authored and sindresorhus committed Nov 4, 2016
1 parent 4e663df commit 77dde6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ function assertPatternsInput(patterns) {
}
}

function castArray(value) {
return Array.isArray(value) ? value : [value];
}

function generateGlobTasks(patterns, opts) {
patterns = Array.isArray(patterns) ? patterns : [patterns];
patterns = castArray(patterns);
assertPatternsInput(patterns);

var globTasks = [];
Expand Down Expand Up @@ -80,3 +84,10 @@ module.exports.sync = function (patterns, opts) {
};

module.exports.generateGlobTasks = generateGlobTasks;

module.exports.hasMagic = function (patterns, opts) {
patterns = castArray(patterns);
return patterns.some(function (pattern) {
return glob.hasMagic(pattern, opts);
});
};
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Type: `Object`

See the `node-glob` [options](https://github.com/isaacs/node-glob#options).

### globby.hasMagic(patterns, [options])

Returns `true` if there are any special glob characters in an array of patterns.

See `node-glob` hasMagic(https://github.com/isaacs/node-glob#globhasmagicpattern-options).


## Globbing patterns

Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ test('expose generateGlobTasks', t => {
t.deepEqual(tasks[0].opts.ignore, ['c.tmp', 'b.tmp']);
});

test('expose hasMagic', t => {
t.true(m.hasMagic('**'));
});

test('hasMagic handles multiple patterns', t => {
t.true(m.hasMagic(['**', 'path1', 'path2']));
t.false(m.hasMagic(['path1', 'path2']));
});

// rejected for being an invalid pattern
[
{},
Expand Down

0 comments on commit 77dde6d

Please sign in to comment.