Comparing version 1.3.0 to 1.4.0
@@ -12,4 +12,6 @@ // Generated by CoffeeScript 1.6.3 | ||
Finder = (function() { | ||
Finder.ASTERISK_PATTERN = '[0-9a-zA-Z/.-_ ]+'; | ||
Finder.ASTERISK_PATTERN = '<[0-9a-zA-Z/.-_ ]+>'; | ||
Finder.ESCAPE_PATTERN = ['.', '[', ']', '\\', '^', '$', '|', '?', '+', '(', ')', '{', '}']; | ||
Finder.TIME_FORMAT = 'YYYY-MM-DD HH:mm'; | ||
@@ -45,3 +47,3 @@ | ||
exclude = excludes[_i]; | ||
result.push(exclude.replace(/\*/g, Finder.ASTERISK_PATTERN)); | ||
result.push(Finder.normalizePattern(exclude)); | ||
} | ||
@@ -98,8 +100,2 @@ this.excludes = this.excludes.concat(result); | ||
} | ||
if (this.systemFiles === false) { | ||
this.exclude('~$'); | ||
} | ||
if (mask !== null) { | ||
mask = mask.replace(/\*/g, Finder.ASTERISK_PATTERN); | ||
} | ||
paths = []; | ||
@@ -154,2 +150,6 @@ _ref = fs.readdirSync(dir); | ||
} | ||
mask = Finder.normalizePattern(mask); | ||
if (this.systemFiles === false) { | ||
this.exclude(['<~$>', '<^\\.>']); | ||
} | ||
return this.getPaths(this.directory, type, mask); | ||
@@ -209,4 +209,2 @@ }; | ||
path = path.substr(0, splitter); | ||
mask = mask.replace(/<|>/g, ''); | ||
path = path.replace(/<|>/g, ''); | ||
} | ||
@@ -237,6 +235,45 @@ return { | ||
default: | ||
throw new Error('Unknown operator ' + operator + '.'); | ||
throw new Error('Unknown operator ' + operator + '.', '^.'); | ||
} | ||
}; | ||
Finder.normalizePattern = function(pattern) { | ||
var i, part, parts, partsResult, replacement, _i, _len; | ||
if (pattern === null) { | ||
return null; | ||
} | ||
if (pattern === '*') { | ||
return null; | ||
} | ||
pattern = pattern.replace(/\*/g, Finder.ASTERISK_PATTERN); | ||
parts = pattern.match(/<((?!(<|>)).)*>/g); | ||
if (parts !== null) { | ||
partsResult = {}; | ||
for (i = _i = 0, _len = parts.length; _i < _len; i = ++_i) { | ||
part = parts[i]; | ||
partsResult['::' + i + '::'] = part.replace(/^<(.*)>$/, '$1'); | ||
pattern = pattern.replace(part, '::' + i + '::'); | ||
} | ||
pattern = Finder.escapeForRegex(pattern); | ||
for (replacement in partsResult) { | ||
part = partsResult[replacement]; | ||
pattern = pattern.replace(replacement, part); | ||
} | ||
} else { | ||
pattern = Finder.escapeForRegex(pattern); | ||
} | ||
return pattern; | ||
}; | ||
Finder.escapeForRegex = function(text) { | ||
var char, replace, _i, _len, _ref; | ||
replace = []; | ||
_ref = Finder.ESCAPE_PATTERN; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
char = _ref[_i]; | ||
replace.push('\\' + char); | ||
} | ||
return text.replace(new RegExp('(' + replace.join('|') + ')', 'g'), '\\$1'); | ||
}; | ||
return Finder; | ||
@@ -243,0 +280,0 @@ |
{ | ||
"name": "fs-finder", | ||
"description": "File system recursive finder", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "David Kudera", |
@@ -46,4 +46,6 @@ # fs-finder | ||
Only thing what you have to do, is enclose your regex into <>. | ||
``` | ||
var files = finder.recursively().findFiles('temp/[0-9]+.tmp'); // files in temp directories with numbers in name and .tmp extension | ||
var files = finder.recursively().findFiles('temp/<[0-9]+>.tmp'); // files in temp directories with numbers in name and .tmp extension | ||
``` | ||
@@ -122,4 +124,2 @@ | ||
Only different thing are regular expressions. They have to be enclosed in <>. | ||
``` | ||
@@ -126,0 +126,0 @@ var files = Finder.findFiles('/var/data/base-path/<(.git|.idea)*[0-9]>'); // Returns every file with .git or .idea and also with number in path |
Sorry, the diff of this file is not supported yet
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
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
16125
244