Comparing version 3.2.1 to 3.3.0
@@ -14,12 +14,12 @@ declare module "fdir" { | ||
type Options = { | ||
includeBasePath: boolean; | ||
includeDirs: boolean; | ||
normalizePath: boolean; | ||
maxDepth: number; | ||
resolvePaths: boolean; | ||
suppressErrors: boolean; | ||
group: boolean; | ||
onlyCounts: boolean; | ||
filter: FilterFn; | ||
exclude: ExcludeFn; | ||
includeBasePath?: boolean; | ||
includeDirs?: boolean; | ||
normalizePath?: boolean; | ||
maxDepth?: number; | ||
resolvePaths?: boolean; | ||
suppressErrors?: boolean; | ||
group?: boolean; | ||
onlyCounts?: boolean; | ||
filter?: FilterFn; | ||
exclude?: ExcludeFn; | ||
}; | ||
@@ -46,3 +46,2 @@ | ||
class Builder { | ||
constructor(options?: Options); | ||
/** | ||
@@ -110,4 +109,12 @@ * Prepend base path to all the paths | ||
* Finalize settings and start crawling | ||
* @param dirPath The path of the directory | ||
*/ | ||
crawl(dirPath: string): APIBuilder; | ||
/** | ||
* Start crawling with custom options | ||
* @param dirPath The path of the directory | ||
* @param options Custom options | ||
*/ | ||
crawlWithOptions(dirPath: string, options: Options): APIBuilder; | ||
} | ||
@@ -114,0 +121,0 @@ |
{ | ||
"name": "fdir", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "The fastest directory crawler for NodeJS. Crawls 10k files in 13ms.", | ||
@@ -9,3 +9,4 @@ "main": "index.js", | ||
"test:coverage": "jest __tests__/fdir.test.js --coverage", | ||
"benchmark": "node benchmark.js" | ||
"bench": "node benchmarks/benchmark.js", | ||
"bench:glob": "node benchmarks/glob-benchmark.js" | ||
}, | ||
@@ -40,8 +41,11 @@ "repository": { | ||
"benny": "^3.6.14", | ||
"fast-glob": "^3.2.2", | ||
"fdir1": "npm:fdir@1.2.0", | ||
"fdir2": "npm:fdir@2.1.0", | ||
"fs-readdir-recursive": "^1.1.0", | ||
"get-all-files": "^1.0.7", | ||
"get-all-files": "^2.0.0", | ||
"glob": "^7.1.6", | ||
"klaw-sync": "^6.0.0", | ||
"mock-fs": "^4.11.0", | ||
"picomatch": "^2.2.2", | ||
"recur-readdir": "0.0.1", | ||
@@ -52,5 +56,4 @@ "recursive-files": "^1.0.2", | ||
"rrdir": "^6.1.2", | ||
"walk-sync": "^2.0.2", | ||
"picomatch": "^2.2.2" | ||
"walk-sync": "^2.0.2" | ||
} | ||
} |
@@ -55,6 +55,3 @@ <p align="center"> | ||
// create the builder | ||
const api = fdir | ||
.new() | ||
.withFullPaths() | ||
.crawl("path/to/dir"); | ||
const api = new fdir().withFullPaths().crawl("path/to/dir"); | ||
@@ -61,0 +58,0 @@ // get all files in a directory synchronously |
@@ -62,16 +62,16 @@ const { sep, resolve: pathResolve } = require("path"); | ||
const { | ||
filter, | ||
onlyCounts, | ||
filterFn, | ||
onlyCountsVar, | ||
includeBasePath, | ||
includeDirs, | ||
group, | ||
exclude, | ||
groupVar, | ||
excludeFn, | ||
} = options; | ||
// build function for adding paths to array | ||
if (filter && onlyCounts) { | ||
pushFile = fns.pushFileFilterAndCount(filter); | ||
} else if (filter) { | ||
pushFile = fns.pushFileFilter(filter); | ||
} else if (onlyCounts) { | ||
if (filterFn && onlyCountsVar) { | ||
pushFile = fns.pushFileFilterAndCount(filterFn); | ||
} else if (filterFn) { | ||
pushFile = fns.pushFileFilter(filterFn); | ||
} else if (onlyCountsVar) { | ||
pushFile = fns.pushFileCount; | ||
@@ -88,10 +88,10 @@ } else { | ||
// build recursive walk directory function | ||
walkDir = exclude ? fns.walkDirExclude(exclude) : fns.walkDir; | ||
walkDir = excludeFn ? fns.walkDirExclude(excludeFn) : fns.walkDir; | ||
// build groupFiles function for grouping files | ||
groupFiles = group ? fns.groupFiles : fns.empty; | ||
getArray = group ? fns.getArrayGroup : fns.getArray; | ||
groupFiles = groupVar ? fns.groupFiles : fns.empty; | ||
getArray = groupVar ? fns.getArrayGroup : fns.getArray; | ||
// build callback invoker | ||
if (onlyCounts) { | ||
if (onlyCountsVar) { | ||
callbackInvoker = isSync | ||
@@ -98,0 +98,0 @@ ? fns.callbackInvokerOnlyCountsSync |
const APIBuilder = require("./apiBuilder"); | ||
var pm = null; | ||
/* istanbul ignore next */ | ||
if (require.resolve("picomatch")) pm = require("picomatch"); | ||
try { | ||
require.resolve("picomatch"); | ||
pm = require("picomatch"); | ||
} catch (_e) { | ||
// do nothing | ||
} | ||
function Builder(options = null) { | ||
this.options = options || { | ||
includeBasePath: false, | ||
includeDirs: false, | ||
normalizePath: false, | ||
maxDepth: Infinity, | ||
resolvePaths: false, | ||
suppressErrors: true, | ||
group: false, | ||
onlyCounts: false, | ||
filter: undefined, | ||
exclude: undefined, | ||
}; | ||
this.options.maxDepth = (options && options.maxDepth) || Infinity; | ||
function Builder() { | ||
this.maxDepth = Infinity; | ||
this.suppressErrors = true; | ||
} | ||
Builder.prototype.crawl = function(path) { | ||
return new APIBuilder(path, this.options); | ||
return new APIBuilder(path, this); | ||
}; | ||
Builder.prototype.crawlWithOptions = function(path, options) { | ||
if (!options.maxDepth) options.maxDepth = Infinity; | ||
options.groupVar = options.group; | ||
options.onlyCountsVar = options.onlyCounts; | ||
options.excludeFn = options.exclude; | ||
options.filterFn = options.filter; | ||
return new APIBuilder(path, options); | ||
}; | ||
Builder.prototype.withBasePath = function() { | ||
this.options.includeBasePath = true; | ||
this.includeBasePath = true; | ||
return this; | ||
@@ -32,3 +35,3 @@ }; | ||
Builder.prototype.withDirs = function() { | ||
this.options.includeDirs = true; | ||
this.includeDirs = true; | ||
return this; | ||
@@ -38,3 +41,3 @@ }; | ||
Builder.prototype.withMaxDepth = function(depth) { | ||
this.options.maxDepth = depth; | ||
this.maxDepth = depth; | ||
return this; | ||
@@ -44,4 +47,4 @@ }; | ||
Builder.prototype.withFullPaths = function() { | ||
this.options.resolvePaths = true; | ||
this.options.includeBasePath = true; | ||
this.resolvePaths = true; | ||
this.includeBasePath = true; | ||
return this; | ||
@@ -51,3 +54,3 @@ }; | ||
Builder.prototype.withErrors = function() { | ||
this.options.suppressErrors = false; | ||
this.suppressErrors = false; | ||
return this; | ||
@@ -57,3 +60,3 @@ }; | ||
Builder.prototype.group = function() { | ||
this.options.group = true; | ||
this.groupVar = true; | ||
return this; | ||
@@ -63,3 +66,3 @@ }; | ||
Builder.prototype.normalize = function() { | ||
this.options.normalizePath = true; | ||
this.normalizePath = true; | ||
return this; | ||
@@ -69,3 +72,3 @@ }; | ||
Builder.prototype.filter = function(filterFn) { | ||
this.options.filter = filterFn; | ||
this.filterFn = filterFn; | ||
return this; | ||
@@ -82,3 +85,3 @@ }; | ||
const isMatch = pm(patterns); | ||
this.options.filter = (path) => { | ||
this.filterFn = (path) => { | ||
return isMatch(path, patterns); | ||
@@ -90,3 +93,3 @@ }; | ||
Builder.prototype.exclude = function(excludeFn) { | ||
this.options.exclude = excludeFn; | ||
this.excludeFn = excludeFn; | ||
return this; | ||
@@ -96,3 +99,3 @@ }; | ||
Builder.prototype.onlyCounts = function() { | ||
this.options.onlyCounts = true; | ||
this.onlyCountsVar = true; | ||
return this; | ||
@@ -99,0 +102,0 @@ }; |
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
21483
486
17
118