Socket
Socket
Sign inDemoInstall

fdir

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fdir - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

9

index.d.ts
declare module "fdir" {
type Options = {
includeDirs?: boolean;
includeBasePath?: boolean;
excludeBasePath?: boolean;
maxDepth?: number;

@@ -17,3 +17,3 @@ searchFn?: (filePath: string) => boolean;

*/
function sync(directoryPath: String, options?: Options): Array<String>;
function sync(directoryPath: string, options?: Options): string[];

@@ -25,8 +25,5 @@ /**

*/
function async(
directoryPath: String,
options?: Options
): Promise<Array<String>>;
function async(directoryPath: string, options?: Options): Promise<string[]>;
export { sync, async };
}

@@ -18,4 +18,7 @@ const fs = require("fs");

if (currentDir === sep) currentDir = "";
const params = { currentDir, paths, options, dirs };
dirents.forEach(function(dirent) {
recurse(dirent, currentDir, paths, options, dirs);
params.dirent = dirent;
recurse(params);
});

@@ -58,5 +61,9 @@ } catch (error) {

if (currentDir === sep) currentDir = "";
const params = { currentDir, paths, options, dirs };
for (var j = 0; j < dirents.length; ++j) {
recurse(dirents[j], currentDir, paths, options, dirs);
params.dirent = dirents[j];
recurse(params);
}
if (readCount === total) walk();

@@ -70,3 +77,4 @@ });

function recurse(dirent, currentDir, paths, options, dirs) {
function recurse(params) {
const { dirent, currentDir, paths, options, dirs } = params;
// In node < 10, Dirent is not present. Instead we get string paths

@@ -84,6 +92,7 @@

if (isDirectory) {
if (options.isExcludedDir && options.isExcludedDir(fullPath)) return;
dirs[dirs.length] = fullPath;
if (!options.isExcludedDir || !options.isExcludedDir(fullPath))
dirs[dirs.length] = fullPath;
return;
}
if (options.excludeBasePath) fullPath = dirName;

@@ -90,0 +99,0 @@ if (!options.searchFn || options.searchFn(fullPath))

{
"name": "fdir",
"version": "2.1.0",
"version": "2.1.1",
"description": "The fastest directory crawler for NodeJS. Crawls 10k files in 13ms.",

@@ -11,2 +11,3 @@ "main": "index.js",

},
"types": "index.d.ts",
"repository": {

@@ -13,0 +14,0 @@ "type": "git",

@@ -17,3 +17,3 @@ <p align="center">

⚡ **Extremely Fast:** Nothing beats `fdir` in speed. It can easily crawl a directory containing **10k files in about 13ms.**
⚡ **Extremely Fast:** Nothing similar (in the NodeJS world) beats `fdir` in speed. It can easily crawl a directory containing **1 million files in < 1 second.**

@@ -24,6 +24,23 @@ 💡 **Stupidly Easy:** `fdir` only has 2 functions; `sync` and `async` for crawling the file system synchronously or asynchronously.

đŸ•ē **Astonishingly Small:** Only 2KB in size. Can be used virtually anywhere.
đŸ•ē **Astonishingly Small:** < 1KB in size
đŸ”Ĩ **All Node Versions Supported:** `fdir` runs everywhere on all Node versions (within reason). And it is unsurprisingly fastest there too.
## Support
> Do you like this project? **[Support me by donating](https://ko-fi.com/thecodrr)**, creating an issue, becoming a stargazer or opening a pull request. Thanks.
## Status
I am currently polishing up the new **3.0** release. I have improved performance by 30%, optimized memory allocations, added new options and a bunch of other stuff you'll love! Here's a question: Should I add a Builder API? Something like this:
```js
fdir.withDirs()
.withCounts()
.withSearch()
.withBasePath()
.crawl("node_modules");
```
[Leave your thoughts at this issue.](https://github.com/thecodrr/fdir/issues/13)
## 🚄 Quickstart

@@ -34,3 +51,3 @@

```sh
$ npm i --save fdir
$ npm i fdir
```

@@ -70,3 +87,3 @@

- OS: Manjaro Linux
- Directory Size: 7386 files
- Directory Size: 9847 files, 1620 folders

@@ -76,6 +93,13 @@ **Notes:**

- Some people asked that I benchmark `no-op` (without options) version of `fdir`. I did and found no performance difference. The results were identical. (I didn't include it here as it wasn't anything special.)
- Some other people were doubtful about the authenticity of these results due to _frequency scaling_, _process overload_, _disk warmup_ etc. So I have updated the benchmark with new results that should resolve all those doubts. Here's the process I followed:
- Hard shutdown the laptop (a couple of times just to be sure) to clear disk, ram cache etc.
- Login directly to a TTY (avoiding any unnecessary process from starting).
- Run the benchmark
- Alright, I will say it as it is. I am not an expert at benchmarking so feel free to advise me as to the correct way of doing this.
### Node v13.11.0:
| Synchronous (7386 files) | Asynchronous (7386 files) |
_Last updated: March 30, 2020 (fdir v2.1.0)_
| Synchronous | Asynchronous |
| :---------------------------------------------------------------------: | :----------------------------------------------------------------------: |

@@ -94,31 +118,70 @@ | ![](https://github.com/thecodrr/fdir/raw/master/assets/node13-sync.png) | ![](https://github.com/thecodrr/fdir/raw/master/assets/node13-async.png) |

`fdir` is very small so there's not much to the API.
### Asynchronous
### `fdir.sync(string, Options): String[]`
```ts
fdir.async(directoryPath: string, options?: Options): Promise<String[]>
```
This is often the fastest way to get files. However, it will block the main "thread" so use it with caution with large directories.
- **Returns:** A `Promise` containing an array of file paths
### `fdir.async(string, Options): Promise<String[]>`
```js
const fdir = require("fdir");
Not always the fastest but works without blocking the street, so that's a plus.
const files = await fdir.async("node_modules", { ignoreErrors: true });
### `Options`
// ["file1", "file2" ,...., "fileN"]
```
Ah, the options. Not many of them. At least not as many as I'd hoped for.
### Synchronous
#### `includeDirs: boolean`
```ts
fdir.sync(directoryPath: string, options?: Options): String[]
```
- **Returns:** An array of all the files in `directoryPath`.
```js
const fdir = require("fdir");
const files = fdir.sync("node_modules", { ignoreErrors: true });
// ["file1", "file2" ,...., "fileN"]
```
#### `directoryPath`:
- **Required:** `true`
- **Type:** `string`
The path of the directory from where fdir should start.
#### `options`:
- **Required:** `false`
- **Type:** [`Options`](#options-1)
See [Options](#options-1) section.
### Options
#### `includeDirs`
- **Type:** `boolean`
- **Default:** `false`
Whether to include directories in the array returned.
`default: false`
#### `excludeBasePath`
#### `excludeBasePath: boolean`
- **Type:** `boolean`
- **Default:** `false`
Whether to exclude the base path for each file.
`default: false`
#### `searchFn`
#### `searchFn: Function`
- **Type:** `Function`
- **Default:** `undefined`
Use this to filter out files.
Use this to filter out specific files, apply a glob pattern etc.

@@ -131,13 +194,17 @@ **Example:**

});
// [".git/.config"]
```
`default: undefined`
#### `maxDepth`
#### `maxDepth: number`
- **Type:** `number`
- **Default:** `Infinity`
The max number of levels `fdir` should crawl before stopping. **The lower the faster.**
`default: undefined (i.e. infinity)`
#### `isExcludedDir`
#### `isExcludedDir: Function`
- **Type:** `boolean`
- **Default:** `Function`

@@ -153,6 +220,9 @@ Use this to exclude particular directories from being crawled.

`default: undefined`
#### `ignoreErrors`
And that's it.
- **Type:** `boolean`
- **Default:** `false`
Ignore/suppress all errors while traversing the file system. This will ignore every single error without exception, skipping the errored directories.
## ⁉ī¸ FAQs:

@@ -184,16 +254,4 @@

**7. Are you looking for a job?**
Am I? Well, are you offering a job? If yes, I am interested. :D
**8. Why should I care?**
You shouldn't. But here's my email in case you do: **thecodrr[at]protonmail.com**. Don't worry, I don't bite.
## ℹī¸ Support
Would love if you buy me a cup of coffee [right over here](https://ko-fi.com/thecodrr). Or just be, you know, polite and give me a star? Maybe even follow me?
## đŸĻŽ LICENSE
Copyright (c) 2020 Abdullah Atta under MIT. [Read full text here.](https://github.com/thecodrr/fdir/raw/master/LICENSE)
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