Socket
Socket
Sign inDemoInstall

readdir-glob

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readdir-glob - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

35

index.js

@@ -62,3 +62,3 @@ module.exports = readdirGlob;

async function* exploreWalkAsync(dir, path, followSyslinks, useStat, strict) {
async function* exploreWalkAsync(dir, path, followSyslinks, useStat, shouldSkip, strict) {
let files = await readdir(path + dir, strict);

@@ -75,11 +75,14 @@ for(const file of files) {

yield {relative, absolute, stats};
if(stats.isDirectory()) {
yield* exploreWalkAsync(filename, path, followSyslinks, useStat, false);
if(!shouldSkip(relative)) {
yield {relative, absolute, stats};
yield* exploreWalkAsync(filename, path, followSyslinks, useStat, shouldSkip, false);
}
} else {
yield {relative, absolute, stats};
}
}
}
async function* explore(path, followSyslinks, useStat) {
yield* exploreWalkAsync('', path, followSyslinks, useStat, true);
async function* explore(path, followSyslinks, useStat, shouldSkip) {
yield* exploreWalkAsync('', path, followSyslinks, useStat, shouldSkip, true);
}

@@ -96,2 +99,3 @@

ignore: options.ignore,
skip: options.skip,

@@ -120,3 +124,3 @@ follow: !!options.follow,

this.matchers = matchers.map( m =>
new Minimatch(this.options.pattern, {
new Minimatch(m, {
dot: this.options.dot,

@@ -137,4 +141,12 @@ noglobstar:this.options.noglobstar,

}
this.skipMatchers = [];
if(this.options.skip) {
const skipPatterns = Array.isArray(this.options.skip) ? this.options.skip : [this.options.skip];
this.skipMatchers = skipPatterns.map( skip =>
new Minimatch(skip, {dot: true})
);
}
this.iterator = explore(resolve(cwd || '.'), this.options.follow, this.options.stat);
this.iterator = explore(resolve(cwd || '.'), this.options.follow, this.options.stat, this._shouldSkipDirectory.bind(this));
this.paused = false;

@@ -154,5 +166,10 @@ this.inactive = false;

_shouldSkipDirectory(relative) {
//console.log(relative, this.skipMatchers.some(m => m.match(relative)));
return this.skipMatchers.some(m => m.match(relative));
}
_fileMatches(relative, isDirectory) {
const file = relative + (isDirectory ? '/' : '');
return this.matchers.every(m => m.match(file))
return (this.matchers.length === 0 || this.matchers.some(m => m.match(file)))
&& !this.ignoreMatchers.some(m => m.match(file))

@@ -159,0 +176,0 @@ && (!this.options.nodir || !isDirectory);

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

"description": "Recursive fs.readdir with streaming API and glob filtering.",
"version": "1.0.0",
"version": "1.1.0",
"homepage": "https://github.com/Yqnn/node-readdir-glob",

@@ -20,2 +20,3 @@ "repository": {

"devDependencies": {
"coveralls": "^3.1.0",
"jest": "^26.1.0",

@@ -39,4 +40,5 @@ "mkdirp": "^1.0.0",

"scripts": {
"test": "jest --collect-coverage",
"test-regen": "TEST_REGEN=1 jest --collect-coverage",
"test": "jest --coverage",
"test-regen": "TEST_REGEN=1 jest --coverage",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"bench": "bash scripts/benchmark.sh",

@@ -43,0 +45,0 @@ "profile": "bash scripts/profile.sh && cat profile.txt"

# Readdir-Glob
[![Build Status](https://travis-ci.com/Yqnn/node-readdir-glob.svg?branch=master)](https://travis-ci.com/Yqnn/node-readdir-glob)
[![Build Status](https://travis-ci.com/Yqnn/node-readdir-glob.svg?branch=master)](https://travis-ci.com/Yqnn/node-readdir-glob) [![Coverage Status](https://coveralls.io/repos/github/Yqnn/node-readdir-glob/badge.svg?branch=master)](https://coveralls.io/github/Yqnn/node-readdir-glob?branch=master)

@@ -33,6 +33,6 @@ Recursive version of fs.readdir wih stream API and glob filtering.

* `root` `{String}` Pattern to be matched
* `options` `{Object}`
* `root` `{String}` Path to be read recursively, *default*: `'.'`
* `options` `{Object}` Options, *default*: `{}`
Returns a EventEmitter reding given root recursively.
Returns a EventEmitter reading given root recursively.

@@ -59,4 +59,5 @@ ### Properties

* `pattern`: Glob pattern or Array of Glob patterns to match the found files with.
* `ignore`: Glob pattern or Array of Glob patterns to exclude matches. Note: `ignore` patterns are *always* in `dot:true` mode.
* `pattern`: Glob pattern or Array of Glob patterns to match the found files with. A file has to match at least one of the provided patterns to be returned.
* `ignore`: Glob pattern or Array of Glob patterns to exclude matches. If a file or a folder matches at least one of the provided patterns, it's not returned. It doesn't prevent files from folder content to be returned. Note: `ignore` patterns are *always* in `dot:true` mode.
* `skip`: Glob pattern or Array of Glob patterns to exclude folders. If a folder matches one of the provided patterns, it's not returned, and it's not explored: this prevents any of its children to be returned. Note: `skip` patterns are *always* in `dot:true` mode.
* `mark`: Add a `/` character to directory matches.

@@ -77,2 +78,2 @@ * `stat`: Set to true to stat *all* results. This reduces performance.

Unit-test set is based on [node-glob](https://www.npmjs.com/package/glob) tests.
Unit-test set is based on [node-glob](https://www.npmjs.com/package/glob) tests.
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