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

co-readdir

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-readdir - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.jshintignore

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;

11

package.json
{
"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);
}));
});
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