# shrub

> Manipulate lists of files recursively in Node. Chainable API with a promise ending.

Latest version **0.2.0** (published 2013-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install shrub
pnpm add shrub
yarn add shrub
bun add shrub
```

## 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.2.0 |
| Published | 2013-11-23 |
| First published | 2013-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Scott Corgan |
| Maintainers | scottcorgan |
| Keywords | filter, file, size, stats |

## Links

- npm: https://www.npmjs.com/package/shrub
- Repository: https://github.com/scottcorgan/shrub
- Issues: https://github.com/scottcorgan/shrub/issues
- npm.io page: https://npm.io/package/shrub

## Dependencies (2)

- [walk](https://npm.io/package/walk.md) ~2.2.1
- [async](https://npm.io/package/async.md) ~0.2.9

## 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.2.0 (latest) — 2013-11-23
- 0.1.0 — 2013-11-22

## README

# Shrub

Manipulate lists of files recursively in Node. Chainable API with a promise ending.

## Install

```
npm install shrub --save
```

## Usage

```js
var shrub = require('shrub');

shrub('path/to/dir')
  .each(function (filePath, stats, next) {
    // Do something here
    next();
  })
  .filter(function (filePath, stats, next) {
    // Works the same as Array.prototype.filter
    next(true);
  }).then(function (files) {
    // All done
  });
```

## Methods

### each(callback)

Asynchronous loop through file tree Returns an array. The ` next ` callback takes no arguments.

```js
shrub('path/to/dir').each(function (filePath, stats, next) {
  next();
}).then(function (files) {

});
```

### filter(callback)

Aynchronously filter the file tree. Returns an array. The ` next ` callback takes a truthy value and will filter similar to ` Array.prototype.filter `.

```js
shrub('path/to/dir').filter(function (filePath, stats, next) {
  var isValidSize = stats.size < 10000;
  next(isValidSize);
}).then(function (filteredFiles) {
  
});
```

### find(callback)

Asynchronously find a single item in the files true. Returns a single object. The ` next ` callback takes a truth value and will return the first item in the file list that is true.

```js
shrub('path/to/dir').find(function (filePath, stats, next) {
  var isFile = stats.name ='somefile.js';
  next(isFile);
}).then(function (file) {
  
});
```

### then(callback)

Promise-looking callback after all the manipulation methods have fun. Receives a ` files ` value as the only arguments (is a single object of a file if the last manipulation method is ` filter `).

```js
var s = shrub('path/to/dir')
  .each(function (filePath, stats, next) {
    // Do something here
    next();
  })
  .filter(function (filePath, stats, next) {
    next(stats.size < 1);
  });

// Then, somewhere else.
s.then(function (files) {
  // All done
});
```

## Run tests

```
npm install
npm test
```

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