New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fs-expand

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-expand - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test/fixtures/README.md

127

index.js

@@ -6,5 +6,5 @@ 'use strict';

var glob = require('glob');
var _ = require('underscore');
var async = require('async');
var glob = require('glob');
var _ = require('underscore');
var async = require('async');

@@ -15,79 +15,78 @@ // Process specified wildcard glob patterns or filenames against a

// Filepaths to return.
var result = [];
// Iterate over flattened patterns array.
_.flatten(patterns).forEach(function(pattern) {
// If the first character is ! it should be omitted
var exclusion = pattern.indexOf('!') === 0;
// If the pattern is an exclusion, remove the !
if (exclusion) {
pattern = pattern.slice(1);
}
// Find all matching files for this pattern.
var matches = fn(pattern);
// Filepaths to return.
var result = [];
// Iterate over flattened patterns array.
_.flatten(patterns).forEach(function(pattern) {
// If the first character is ! it should be omitted
var exclusion = pattern.indexOf('!') === 0;
// If the pattern is an exclusion, remove the !
if (exclusion) {
pattern = pattern.slice(1);
}
// Find all matching files for this pattern.
var matches = fn(pattern);
if (exclusion) {
// If an exclusion, remove matching files.
result = _.difference(result, matches);
} else {
// Otherwise add matching files.
result = _.union(result, matches);
}
});
return result;
if (exclusion) {
// If an exclusion, remove matching files.
result = _.difference(result, matches);
} else {
// Otherwise add matching files.
result = _.union(result, matches);
}
});
return result;
}
function expand (patterns, options, callback) {
patterns = Array.isArray(patterns) ? patterns : [patterns];
function expand(patterns, options, callback) {
patterns = Array.isArray(patterns) ? patterns : [patterns];
if ( typeof options === 'function' ) {
callback = options;
options = {};
}
if (typeof options === 'function') {
callback = options;
options = {};
}
async.parallel(
patterns.map(function (pattern) {
return function (done) {
glob(pattern, options, done);
};
}),
async.parallel(
patterns.map(function(pattern) {
return function(done) {
glob(pattern, options, done);
};
}),
function (err, results) {
if ( err ) {
return callback(err);
}
function(err, results) {
if (err) {
return callback(err);
}
var result = [];
var result = [];
patterns.forEach(function(pattern, i) {
var exclusion = pattern.indexOf('!') === 0;
patterns.forEach(function (pattern, i) {
var exclusion = pattern.indexOf('!') === 0;
if (exclusion) {
result = _.difference(result, results[i]);
} else {
result = _.union(result, results[i]);
}
});
if ( exclusion ) {
result = _.difference(result, results[i]);
} else {
result = _.union(result, results[i]);
}
});
callback(null, result);
}
);
callback(null, result);
}
);
}
function expandSync (patterns, options) {
// Use the first argument if it's an Array, otherwise convert the arguments
// object to an array and use that.
patterns = Array.isArray(patterns) ? patterns : [patterns];
function expandSync(patterns, options) {
// Use the first argument if it's an Array, otherwise convert the arguments
// object to an array and use that.
patterns = Array.isArray(patterns) ? patterns : [patterns];
return patterns.length === 0 ? [] :
return patterns.length === 0 ? [] :
processPatterns(patterns, function(pattern) {
processPatterns(patterns, function(pattern) {
// Find all matching files for this pattern.
return glob.sync(pattern, options);
});
// Find all matching files for this pattern.
return glob.sync(pattern, options);
});
}
{
"name": "fs-expand",
"version": "0.1.2",
"version": "0.1.3",
"description": "An extended fs glob",

@@ -29,6 +29,6 @@ "main": "index.js",

"dependencies": {
"async": "~0.2.10",
"underscore": "~1.6.0",
"glob": "~3.2.8"
"glob": "~4.0.2",
"async": "~0.9.0"
}
}

@@ -5,2 +5,7 @@ # fs-expand [![NPM version](https://badge.fury.io/js/fs-expand.png)](http://badge.fury.io/js/fs-expand) [![Build Status](https://travis-ci.org/kaelzhang/node-fs-expand.png?branch=master)](https://travis-ci.org/kaelzhang/node-fs-expand) [![Dependency Status](https://gemnasium.com/kaelzhang/node-fs-expand.png)](https://gemnasium.com/kaelzhang/node-fs-expand)

The difference from [`glob`](http://www.npmjs.org/package/glob) is that `fs-expand`
- could combine the results of several glob patterns.
- supports negative matching patterns, such as '!*.js'
## expand(pattern, [options], callback);

@@ -17,7 +22,16 @@

```
dir/
|-- a.js
|-- b.js
|-- README.md
```
```js
var expand = require('fs-expand');
expand('*.js', function(err, files){
console.log(files); // ['a.js', 'b.js']
expand(['*.js', '*.md'], {
cwd: dir
}, function(err, files){
console.log(files); // ['a.js', 'b.js', README.md]
});

@@ -24,0 +38,0 @@ ```

@@ -10,32 +10,45 @@ 'use strict';

describe("expand", function(){
it("async", function(done){
expand([
'*.js',
'!c.js'
], {
cwd: fixtures
}, function (err, files) {
expect(err).to.equal(null);
expect(files.sort()).to.deep.equal([
'a.js',
'b.js'
]);
done();
});
describe("expand", function() {
it("async", function(done) {
expand([
'*.js',
'!c.js'
], {
cwd: fixtures
}, function(err, files) {
expect(err).to.equal(null);
expect(files.sort()).to.deep.equal([
'a.js',
'b.js'
]);
done();
});
});
it("sync", function(){
var files = expand.sync([
'*.js',
'!c.js'
], {
cwd: fixtures
});
it("sync", function() {
var files = expand.sync([
'*.js',
'!c.js'
], {
cwd: fixtures
});
expect(files.sort()).to.deep.equal([
'a.js',
'b.js'
]);
expect(files.sort()).to.deep.equal([
'a.js',
'b.js'
]);
});
it("should maintain order", function(done){
expand([
'*.js',
'*.md'
], {
cwd: fixtures
}, function (err, files) {
expect(err).to.equal(null);
expect(files.pop()).to.equal('README.md');
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc