# fs-crawl

> File system operations utilities that calls your functions on different events for more versatility.

Latest version **0.3.0** (published 2018-11-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install fs-crawl
pnpm add fs-crawl
yarn add fs-crawl
bun add fs-crawl
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-11-26 |
| First published | 2018-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Salvador Ortega |
| Maintainers | salortega |
| Keywords | nodejs, fs, file, system, asynchronous, promise-based |

## Links

- npm: https://www.npmjs.com/package/fs-crawl
- Repository: https://github.com/salvadorOrtega/fs-crawl
- Homepage: https://github.com/salvadorOrtega/fs-crawl#readme
- Issues: https://github.com/salvadorOrtega/fs-crawl/issues
- npm.io page: https://npm.io/package/fs-crawl

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2018-11-26
- 0.2.1 — 2018-11-26
- 0.2.0 — 2018-11-26

## README

# fs-crawl
File system operations utilities for node.js that calls your functions on different events for more versatility.

## API

The motivation for fs-crawl's API is to be able to run callback functions when crawling a directory in an asynchronous and promised fashion.

fs-crawl uses this model to, for example, create an entire directory structure from an object:

```javascript
const myDirectoryObj = {
  'daddyFolder': {
    'child.txt': null,  
    'child2.txt': null,
    'childDir1': {
      'grandChild.txt': null
    },
    'childDir2': {}
  },
  'uncleFolder': {},
}

```
Notice fs-crawl expects the following: 
  * file names must point to `null`
  * a key pointing to an empty object means that key specifies an empty directory

Storing the fs-crawl export in a variable called crawl, and specifying a destination called `intoDirPath`, we turn our object into a directory using crawl.objToDir:

```javascript
crawl.objToDir(myDirectoryObj, intoDirPath);
```

In this case crawl.objToDir passes two callback functions to another fs-crawl utility `crawl.crawlDirObj` that visits our entire myDirectoryObj running a callback function that creates a file when `crawl.crawlDirObj` encounters a key that points to null, and running another callback function that creates a directory when `crawl.crawlDirObj` encounters a key that points to another object.

All files at a given depth are handled first, then all subdirectories.

Similarly, fs-crawl has the `remove()` utility that visits a specified absolute path, runs `crawl.crawlDir()` in this case to visit the contents of that directory rather than the contents of an object, and runs two internal callback functions: one that removes a file when one has been found, and another that removes the directory once its depths have been cleared. Basically, fs-crawl gets to all the files at a certain point in the call stack fist, and into the directories depth-first.

`crawl.copyOneToMany(fromPath, destinationsArray)` copies the contents inside `fromPath` into an arbitrary number of destinations listed in destinationsArray. It first runs `crawl.dirToObj` to obtain a copy of the directory structure as an
object (i.e. the opposite of `crawl.objToDir`), then runs callbacks that copy each directory and file it encounters into each of the destinations.

The pattern of running callback functions when a directory or a file is found allows for easily building composable and ever more powerful file system management tools all while staying within the asynchronous and promises territory.

---
_Source: https://npm.io/package/fs-crawl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
