Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose .hasMagic() #36

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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