path-filters
Advanced tools
Comparing version 1.0.0 to 1.0.1
47
index.js
@@ -20,3 +20,3 @@ var fs = require('fs'); | ||
RegExpFilter.prototype.test = function(path) { | ||
return path.test(filter) ? this._matchResult || true : false; | ||
return this._regex.test(path) ? this._matchResult || true : false; | ||
} | ||
@@ -122,8 +122,14 @@ | ||
var filters = filter; | ||
var result = new Array(filters.length); | ||
for (var i = 0, len = filters.length; i < len; i++) { | ||
this.add(filters[i], recursive, matchResult); | ||
result[i] = filter = this.createFilter(filters[i], recursive, matchResult); | ||
this._filters.push(filter); | ||
} | ||
return this; | ||
return result; | ||
} else { | ||
return this.createFilter(filter, recursive, matchResult); | ||
} | ||
} | ||
PathFilters.prototype.createFilter = function(filter, recursive, matchResult) { | ||
var filterImpl; | ||
@@ -133,29 +139,34 @@ | ||
if (isSimpleRegExp(filter)) { | ||
filterImpl = new RegExpFilter(createSimpleRegExp(filter), matchResult); | ||
return new RegExpFilter(createSimpleRegExp(filter), matchResult); | ||
} else { | ||
try { | ||
var stat = fs.statSync(filter); | ||
if (stat.isFile()) { | ||
recursive = false; | ||
} | ||
} catch(e) { | ||
// ignore | ||
} | ||
filterImpl = new StringFilter(filter, recursive, matchResult); | ||
return this.createSimpleFilter(filter, recursive, matchResult); | ||
} | ||
} else if (filter.constructor === RegExp) { | ||
filterImpl = new RegExpFilter(filter, matchResult); | ||
return new RegExpFilter(filter, matchResult); | ||
} else if (typeof filter === 'function') { | ||
filterImpl = new FunctionFilter(filter, matchResult); | ||
return new FunctionFilter(filter, matchResult); | ||
} else { | ||
throw new Error("Invalid filter: " + filter + " (" + (typeof filter) + ")"); | ||
} | ||
} | ||
this._filters.push(filterImpl); | ||
PathFilters.prototype.createSimpleFilter = function(filter, recursive, matchResult) { | ||
try { | ||
var stat = fs.statSync(filter); | ||
if (stat.isFile()) { | ||
recursive = false; | ||
} | ||
} catch(e) { | ||
// ignore | ||
} | ||
return this; | ||
return new StringFilter(filter, recursive, matchResult); | ||
} | ||
PathFilters.prototype.isEmpty = function() { | ||
return (this._filters.length === 0); | ||
} | ||
module.exports = { | ||
PathFilters: PathFilters, | ||
create: function() { | ||
@@ -162,0 +173,0 @@ return new PathFilters(); |
{ | ||
"name": "path-filters", | ||
"description": "Manages a collection of path-based filters", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/philidem/node-path-filters", | ||
@@ -6,0 +6,0 @@ "authors": [ |
Sorry, the diff of this file is not supported yet
49975
164