Comparing version 0.0.1 to 0.1.0
102
index.js
@@ -8,49 +8,85 @@ 'use strict'; | ||
* | ||
* @example | ||
* ## Examples: | ||
* | ||
* ``` | ||
* expand('../*.js', function (err, jsfiles) { | ||
* globs('../*.js', function (err, jsfiles) { | ||
* console.log(jsfiles); | ||
* }) | ||
* ``` | ||
* @example | ||
* ``` | ||
* expand(['*.js', '../*.js'], function (err, jsfiles) { | ||
* | ||
* globs(['*.js', '../*.js'], function (err, jsfiles) { | ||
* console.log(jsfiles) | ||
* }) | ||
* | ||
* globs(['*.js', '../*.js'], { cwd: '/foo' }, function (err, jsfiles) { | ||
* console.log(jsfiles) | ||
* }) | ||
* ``` | ||
* | ||
* @param {String|Array} patterns One or more patterns to match | ||
* @param {Object} [options] Options | ||
* @param {Function} callback Function which accepts two parameters: err, files | ||
*/ | ||
function expand(patterns, callback) { | ||
var pending, | ||
groups = []; | ||
var globs = module.exports = function (patterns, options, callback) { | ||
var pending | ||
, groups = []; | ||
// not an Array? make it so! | ||
if (!Array.isArray(patterns)) { | ||
patterns = [ patterns ]; | ||
} | ||
// not an Array? make it so! | ||
if (!Array.isArray(patterns)) { | ||
patterns = [ patterns ]; | ||
} | ||
pending = patterns.length; | ||
pending = patterns.length; | ||
// walk the patterns | ||
patterns.forEach(function (pattern) { | ||
// grab the files | ||
glob(pattern, function (err, files) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// parameter shifting is really horrible, but i'm | ||
// mimicing glob's api... | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
// add the files to the group | ||
groups = groups.concat(files); | ||
// walk the patterns | ||
patterns.forEach(function (pattern) { | ||
// grab the files | ||
glob(pattern, options, function (err, files) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
pending -= 1; | ||
// last pattern? | ||
if (!pending) { | ||
// done | ||
return callback(null, groups); | ||
} | ||
}); | ||
}); | ||
} | ||
// add the files to the group | ||
groups = groups.concat(files); | ||
module.exports = expand; | ||
pending -= 1; | ||
// last pattern? | ||
if (!pending) { | ||
// done | ||
return callback(null, groups); | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Synchronously Expand one or more patterns to an Array of files | ||
* | ||
* @api public | ||
* @param {String|Array} patterns | ||
* @param {Object} [options] | ||
* @return {Array} | ||
*/ | ||
globs.sync = function (patterns, options) { | ||
options = options || {}; | ||
var groups = [] | ||
, index | ||
, length; | ||
if (!Array.isArray(patterns)) { | ||
patterns = [ patterns ]; | ||
} | ||
for (index = 0, length = patterns.length; index < length; index++) { | ||
groups = groups.concat(glob.sync(patterns[index], options)); | ||
} | ||
return groups; | ||
}; |
{ | ||
"name": "globs", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Stephen Mathieson", |
@@ -28,4 +28,18 @@ # globs | ||
// sync | ||
var files = globs.sync([ '**/*.js', '/foo/bar/*.coffee' ], { option: 'stuff' }); | ||
``` | ||
## Revision History | ||
### 0.1.0 | ||
- Added sync support (`globs.sync(patterns)`) | ||
### 0.0.1 | ||
- Initial release | ||
- Supports `globs(patterns/pattern)` | ||
[glob]: https://github.com/isaacs/node-glob |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
3193
78
44
0
1