From d49957af7c1ee3644e13ad5582dd8bb394c89959 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 4 Nov 2016 15:05:25 +0700 Subject: [PATCH] cleanup #36 --- index.js | 9 ++------- readme.md | 14 +++++++------- test.js | 3 --- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 6cee921..587a0fd 100644 --- a/index.js +++ b/index.js @@ -21,12 +21,8 @@ function assertPatternsInput(patterns) { } } -function castArray(value) { - return Array.isArray(value) ? value : [value]; -} - function generateGlobTasks(patterns, opts) { - patterns = castArray(patterns); + patterns = [].concat(patterns); assertPatternsInput(patterns); var globTasks = []; @@ -86,8 +82,7 @@ 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 [].concat(patterns).some(function (pattern) { return glob.hasMagic(pattern, opts); }); }; diff --git a/readme.md b/readme.md index 3d2141b..e10a488 100644 --- a/readme.md +++ b/readme.md @@ -44,9 +44,15 @@ Returns an array of objects in the format `{ pattern: string, opts: Object }`, w Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration. +### globby.hasMagic(patterns, [options]) + +Returns a `boolean` of whether there are any special glob characters in the `patterns`. + +Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. + #### patterns -Type: `string`, `Array` +Type: `string` `Array` See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). @@ -56,12 +62,6 @@ 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 diff --git a/test.js b/test.js index d86cfcc..59592d0 100644 --- a/test.js +++ b/test.js @@ -72,9 +72,6 @@ test('expose generateGlobTasks', t => { 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'])); });