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.4 to 0.2.0

28

index.js

@@ -9,2 +9,3 @@ 'use strict';

var async = require('async');
var node_path = require('path');

@@ -40,3 +41,9 @@ // Process specified wildcard glob patterns or filenames against a

function isGlob (pattern) {
return ~ pattern.indexOf('*');
}
// @param {options}
// - globOnly: {Boolean} only deal with glob stars
function expand(patterns, options, callback) {

@@ -52,5 +59,12 @@ patterns = Array.isArray(patterns) ? patterns : [patterns];

async.parallel(
patterns.map(function(pattern) {
patterns
.filter(Boolean)
.map(function(pattern) {
return function(done) {
glob(pattern, options, done);
if (options.globOnly && !isGlob(pattern)) {
pattern = node_path.join('.', pattern);
done(null, [pattern]);
} else {
glob(pattern, options, done);
}
};

@@ -89,6 +103,10 @@ }),

processPatterns(patterns, function(pattern) {
// Find all matching files for this pattern.
return glob.sync(pattern, options);
if (options.globOnly && !isGlob(pattern)) {
pattern = node_path.join('.', pattern);
return [pattern];
} else {
// Find all matching files for this pattern.
return glob.sync(pattern, options);
}
});
}

2

package.json
{
"name": "fs-expand",
"version": "0.1.4",
"version": "0.2.0",
"description": "An extended fs glob",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -18,3 +18,31 @@ # 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)

### Additioanl `options`
- globOnly `Boolean=false` only process glob patterns, if a file does not contain globstars, `fs-expand` will not check the existence of the file.
```
<cwd>/
|-- a.js
|-- b.js
```
```js
expand([
'*.js',
'abc.md'
], {
cwd: cwd,
globOnly: true
}, function(err, files){
files;
// ->
// [
// 'a.js',
// 'b.js',
// 'abc.md' // actually, abc.md doesn't exist.
// ]
});
```
### Example

@@ -21,0 +49,0 @@

@@ -53,2 +53,16 @@ 'use strict';

});
it("options.globOnly", function(done){
expand([
'*.js',
'abc.md'
], {
cwd: fixtures,
globOnly: true
}, function (err, files) {
expect(err).to.equal(null);
expect(files.pop()).to.equal('abc.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