Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fileset

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

fileset - npm Package Compare versions

Comparing version 0.1.8 to 0.2.1

CHANGELOG.md

64

lib/fileset.js

@@ -1,8 +0,10 @@

var util = require('util'),
minimatch = require('minimatch'),
Glob = require('glob').Glob,
EventEmitter = require('events').EventEmitter;
var util = require('util');
var minimatch = require('minimatch');
var glob = require('glob');
var Glob = glob.Glob;
var EventEmitter = require('events').EventEmitter;
module.exports = fileset;
// Async API
function fileset(include, exclude, options, cb) {

@@ -15,7 +17,7 @@ if (typeof exclude === 'function') cb = exclude, exclude = '';

var em = new EventEmitter,
remaining = includes.length,
results = [];
var em = new EventEmitter;
var remaining = includes.length;
var results = [];
if(!includes.length) return cb(new Error('Must provide an include pattern'));
if (!includes.length) return cb(new Error('Must provide an include pattern'));

@@ -33,3 +35,3 @@ em.includes = includes.map(function(pattern) {

if(!(--remaining)) {
if (!(--remaining)) {
results = results.filter(function(file) {

@@ -51,4 +53,42 @@ return !excludes.filter(function(glob) {

// Sync API
fileset.sync = function filesetSync(include, exclude) {
if (!exclude) exclude = '';
// includes / excludes, either an array or string separated by comma or whitespace
var includes = (typeof include === 'string') ? include.split(/[\s,]/g) : include;
var excludes = (typeof exclude === 'string') ? exclude.split(/[\s,]/g) : exclude;
// Filter out any false positive '' empty strings
includes = includes.filter(function(pattern) { return pattern; });
excludes = excludes.filter(function(pattern) { return pattern; });
// - todo: pass in glob options as last param
var options = { matchBase: true };
// First, glob match on all include patters into a single array
var results = includes.map(function(include) {
return glob.sync(include, options);
}).reduce(function(a, b) {
return a.concat(b);
}, []);
// Then filters out on any exclude match
var ignored = excludes.map(function(exclude) {
return glob.sync(exclude, options);
}).reduce(function(a, b) {
return a.concat(b);
}, []);
// And filter any exclude match
results = results.filter(function(file) {
return !ignored.filter(function(glob) {
return minimatch(file, glob, { matchBase: true });
}).length;
});
return results;
};
fileset.Fileset = function Fileset(pattern, options, cb) {
if (typeof options === 'function') cb = options, options = {};

@@ -59,3 +99,3 @@ if (!options) options = {};

if(typeof cb === 'function') {
if (typeof cb === 'function') {
this.on('error', cb);

@@ -67,3 +107,1 @@ this.on('end', function(matches) { cb(null, matches); });

util.inherits(fileset.Fileset, Glob);

@@ -5,3 +5,3 @@ {

"description": "Wrapper around miniglob / minimatch combo to allow multiple patterns matching and include-exclude ability",
"version": "0.1.8",
"version": "0.2.1",
"homepage": "https://github.com/mklabs/node-fileset",

@@ -14,7 +14,7 @@ "repository": {

"scripts": {
"test": "node tests/test.js"
"test": "node tests/test.js && node tests/test-sync.js"
},
"dependencies": {
"minimatch": "0.x",
"glob": "3.x"
"minimatch": "2.x",
"glob": "5.x"
},

@@ -21,0 +21,0 @@ "licenses": [

@@ -1,2 +0,2 @@

# node-fileset
# node-fileset [![Build Status](https://secure.travis-ci.org/mklabs/node-fileset.png)](http://travis-ci.org/mklabs/node-fileset)

@@ -9,3 +9,3 @@ Exposes a basic wrapper on top of

[![Build Status](https://secure.travis-ci.org/mklabs/node-fileset.png)](http://travis-ci.org/mklabs/node-fileset)
[![NPM](https://nodei.co/npm/fileset.png?downloads=true&stars=true)](https://nodei.co/npm/fileset/)

@@ -17,2 +17,4 @@ Adds multiples patterns matching and exlude ability. This is

*[Changelog](https://github.com/mklabs/node-fileset/blob/master/CHANGELOG.md#changelog)*
## Install

@@ -77,2 +79,10 @@

## Sync usage
```js
var results = fileset.sync('*.md *.js', 'CHANGELOG.md node_modules/**/*.md node_modules/**/*.js');
```
The behavior should remain the same, although it lacks the last `options` arguments to pass to internal `glob` and `minimatch` dependencies.
## Tests

@@ -79,0 +89,0 @@

var EventEmitter = require('events').EventEmitter,
assert = require('assert'),
tests = {};
var EventEmitter = require('events').EventEmitter;
var assert = require('assert');
var tests = {};

@@ -16,4 +16,4 @@ module.exports = test;

function run() {
var specs = Object.keys(tests),
specsRemaining = specs.length;
var specs = Object.keys(tests);
var specsRemaining = specs.length;

@@ -24,5 +24,5 @@ specs.forEach(function(spec) {

// grab the set of asserts for this spec
var shoulds = handler(),
keys = Object.keys(shoulds),
remaining = keys.length;
var shoulds = handler();
var keys = Object.keys(shoulds);
var remaining = keys.length;

@@ -42,3 +42,3 @@ keys.forEach(function(should) {

// till we get to 0
if(!(--remaining)) {
if (!(--remaining)) {
console.log([

@@ -54,3 +54,3 @@ '',

if(!(--specsRemaining)) {
if (!(--specsRemaining)) {
console.log('All done');

@@ -57,0 +57,0 @@ }

var EventEmitter = require('events').EventEmitter,
fileset = require('../'),
assert = require('assert'),
test = require('./helper');
var EventEmitter = require('events').EventEmitter;
var fileset = require('../');
var assert = require('assert');
var test = require('./helper');
// Given a **.coffee pattern
// Given a **.md pattern
test('Given a **.md pattern', function() {

@@ -16,3 +16,3 @@

assert.ok(results.length, 'should return at least one element');
assert.equal(results.length, 1, 'actually, should return only one');
assert.equal(results.length, 2, 'actually, should return only two');
em.emit('end');

@@ -31,3 +31,3 @@ });

assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 4);
assert.equal(results.length, 5);
em.emit('end');

@@ -41,5 +41,6 @@ });

assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 5);
assert.equal(results.length, 7);
assert.deepEqual(results, [
'CHANGELOG.md',
'README.md',

@@ -49,2 +50,3 @@ 'lib/fileset.js',

'tests/helper.js',
'tests/test-sync.js',
'tests/test.js'

@@ -84,3 +86,3 @@ ]);

assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 4);
assert.equal(results.length, 5);
em.emit('end');

@@ -95,5 +97,6 @@ });

assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 5);
assert.equal(results.length, 7);
assert.deepEqual(results, [
'CHANGELOG.md',
'README.md',

@@ -103,2 +106,3 @@ 'lib/fileset.js',

'tests/helper.js',
'tests/test-sync.js',
'tests/test.js'

@@ -105,0 +109,0 @@ ]);

Sorry, the diff of this file is not supported yet

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