Comparing version 1.0.0 to 1.0.1
33
index.js
var fs = require('co-fs'); | ||
var each = require('co-each'); | ||
var join = require('path').join; | ||
var minimatch = require('minimatch'); | ||
function* readDir(dir, filter) { | ||
function* readDir(dir, ignore, filter) { | ||
if(typeof ignore === 'function') filter = ignore; | ||
var filterFn = typeof filter === 'undefined' ? noDotFiles : filter; | ||
@@ -11,6 +14,8 @@ var out = []; | ||
var nodes = yield fs.readdir(dir); | ||
if (!fs.existsSync(dir)) return; | ||
var exist = yield fs.exists(dir); | ||
if(!exist) return; | ||
yield each(nodes.filter(filterFn), function* (node) { | ||
var path = join(dir, node); | ||
var match = false; | ||
@@ -21,10 +26,22 @@ var stats = yield fs.lstat(path); | ||
} | ||
if(ignore) { | ||
match = yield miniMatch(path, ignore); | ||
} | ||
out.push(path); | ||
!match && out.push(path); | ||
}); | ||
return out; | ||
} | ||
return yield walk(dir); | ||
return yield walk(dir); | ||
} | ||
function* miniMatch(str, ignore) { | ||
var opts = { | ||
matchBase: true | ||
}; | ||
if (!hasGlob(ignore)) return; | ||
return minimatch(str, ignore, opts); | ||
} | ||
function noDotFiles(x) { | ||
@@ -34,2 +51,6 @@ return x[0] !== '.'; | ||
module.exports = readDir; | ||
function hasGlob(x) { | ||
return ~x.indexOf('*'); | ||
} | ||
module.exports = readDir; |
{ | ||
"name": "co-readdir", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "walk a file tree and return a list of files", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jshint ." | ||
}, | ||
@@ -15,9 +15,10 @@ "keywords": [ | ||
"dependencies": { | ||
"co": "~3.0.4", | ||
"co": "~4.5.1", | ||
"co-fs": "~1.2.0", | ||
"co-each": "~0.1.0", | ||
"unglob": "~0.1.1" | ||
"minimatch": "~0.2.14" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~2.2.1" | ||
"mocha": "~2.2.1", | ||
"jshint": "*" | ||
}, | ||
@@ -24,0 +25,0 @@ "directories": { |
@@ -9,4 +9,2 @@ #co-readdir | ||
# Usage | ||
--- | ||
@@ -16,11 +14,19 @@ 参数: | ||
- `dir`: directory | ||
- 'ignore': minimatch | ||
- `filter`: type function | ||
# Usage | ||
--- | ||
``` | ||
var readDir = require('co-readdir'); | ||
co(function* () { | ||
var folder = 'test/fixtures/basic'; | ||
var actual = yield readDir(folder); | ||
console.log(actual); | ||
var ignore = '*.js'; | ||
function filter(x) { | ||
return x[0] !== '.'; | ||
} | ||
var actual = yield readDir(folder, ignore, filter); | ||
})(); | ||
``` |
@@ -10,11 +10,20 @@ var relative = require('path').relative; | ||
it('should walk a folder', co(function* () { | ||
var folder = 'test/fixtures/basic' | ||
var actual = yield walk(folder) | ||
var folder = 'test/fixtures/basic'; | ||
var actual = yield walk(folder); | ||
var expected = [ | ||
'test/fixtures/basic/app.js' | ||
] | ||
]; | ||
assert.deepEqual(actual, expected) | ||
})) | ||
}); | ||
assert.deepEqual(actual, expected); | ||
})); | ||
it('test ignore', co(function* () { | ||
var folder = 'test/fixtures/basic' | ||
var actual = yield walk(folder, '*.js'); | ||
var expected = []; | ||
assert.deepEqual(actual, expected); | ||
})); | ||
}); |
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
3501
11
63
0
30
2
+ Addedminimatch@~0.2.14
+ Addedco@4.5.4(transitive)
- Removedunglob@~0.1.1
- Removedco@3.0.6(transitive)
- Removedgenerator-supported@0.0.1(transitive)
- Removedglob@3.2.11(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedunglob@0.1.2(transitive)
Updatedco@~4.5.1