# recrawl

> [![npm](https://img.shields.io/npm/v/recrawl.svg)](https://www.npmjs.com/package/recrawl) [![ci](https://github.com/aleclarson/recrawl/actions/workflows/release.yml/badge.svg)](https://github.com/aleclarson/recrawl/actions/workflows/release.yml) [![codeco

Latest version **2.2.1** (published 2021-04-21) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2021-04-21 |
| First published | 2018-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 29.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | aleclarson |
| Keywords | fs, crawl, crawler, directory, readdir, glob, globby, recrawl, tiny |

## Links

- npm: https://www.npmjs.com/package/recrawl
- Repository: https://github.com/aleclarson/recrawl
- Homepage: https://github.com/aleclarson/recrawl#readme
- Issues: https://github.com/aleclarson/recrawl/issues
- npm.io page: https://npm.io/package/recrawl

## Dependencies (4)

- [slash](https://npm.io/package/slash.md) ^3.0.0
- [tslib](https://npm.io/package/tslib.md) ^1.9.3
- [glob-regex](https://npm.io/package/glob-regex.md) ^0.3.0
- [@cush/relative](https://npm.io/package/@cush/relative.md) ^1.0.0

## 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

- 2.2.1 (latest) — 2021-04-21
- 2.2.0 — 2021-04-20
- 2.1.0 — 2021-04-20
- 2.0.1 — 2021-04-01
- 2.0.0 — 2019-11-11
- 1.2.3 — 2019-10-20
- 1.2.2 — 2019-06-05
- 1.2.1 — 2019-06-05
- 1.2.0 — 2019-06-05
- 1.1.2 — 2019-06-05
- 1.1.1 — 2019-06-05
- 1.1.0 — 2019-06-05
- 1.0.3 — 2019-06-03
- 1.0.2 — 2019-06-02
- 1.0.1 — 2019-06-02
- … 2 more at https://npm.io/package/recrawl/versions

## README

# recrawl

[![npm](https://img.shields.io/npm/v/recrawl.svg)](https://www.npmjs.com/package/recrawl)
[![ci](https://github.com/aleclarson/recrawl/actions/workflows/release.yml/badge.svg)](https://github.com/aleclarson/recrawl/actions/workflows/release.yml)
[![codecov](https://codecov.io/gh/aleclarson/recrawl/branch/master/graph/badge.svg)](https://codecov.io/gh/aleclarson/recrawl)
[![Bundle size](https://badgen.net/bundlephobia/min/recrawl)](https://bundlephobia.com/result?p=recrawl)
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)

Collect the descendants of a directory.

```ts
import { recrawl } from 'recrawl'

// Create a crawl function.
// These are the default options.
const crawl = recrawl({
  only: [],
  skip: [],
  deep: true,
  follow: false,
})

// The result is an array when `follow` is false, else an object.
const files = crawl(root)

// Provide your own array/object.
crawl(root, files)

// Provide an iterator.
crawl(root, (file, link) => {
  // The `file` argument is relative to the root.
  // The `link` argument is null for non-symlinks. It will be absolute if the target is outside the root.
})
```

You can use the `crawl()` export if you don't want to reuse the configured crawler.

```ts
import { crawl } from 'recrawl'

crawl(root, {
  only: [],
  skip: [],
  deep: true,
  follow: false,
})
```

### Options

- `only?: (string|RegExp)[]`
- `skip?: (string|RegExp)[]`
- `absolute?: boolean`
- `deep?: boolean`
- `depth?: number`
- `enter?: function`
- `filter?: function`
- `follow?: boolean|number|function`
- `adapter?: FileAdapter`

The `only` and `skip` options should be self-explanatory. Paths matching any of
the `only` patterns are good. When `only` is an empty array, all paths are good.
Paths matching any of the `skip` patterns are bad. When `skip` is an empty
array, no paths are bad. The `skip` patterns override the `only` patterns.

The `absolute` option converts matching file paths into their absolute form.

To avoid crawling sub-directories, set `deep` to false or `depth` to 0. You
should never define both `deep` and `depth`, because the `depth` option implies
`deep` when it's greater than zero. If neither `deep` nor `depth` are defined,
the default depth is infinite.

The `enter` option is called whenever a directory is encountered. It's passed
the directory path and the current depth. You may return a falsy value to avoid
crawling a directory.

The `filter` option is called whenever a filename is encountered. It's passed
the filename and its basename. You may return a falsy value to skip a filename.
The `only` and `skip` options are applied before this option is called.

To follow all symlinks, set `follow` to true. For greater control, use a
function. It's called whenever a symlink is encountered. You may return a falsy
value to avoid following a symlink. It's passed the symlink path and the current
link depth. If you only need to limit the link depth, you can set `follow` to a
number, where zero is equivalent to false.

The `adapter` option lets you provide your own filesystem.

### Gotchas

- Directory symlinks are treated the same as real directories
- Directories are not affected by the `only` option

### Pattern syntax

Recrawl has its own take on globbing.

1. When a path has no separators (`/`), only the basename is matched.

```js
'*.js' // matches 'a.js' and 'a/b.js'
```

2. Recursivity is implicit.

```js
'a/b' // identical to '**/a/b'
```

3. Use a leading separator to match against the root.

```js
'/*.js' // matches 'a.js' not 'a/b.js'
```

4. Use a trailing separator to match all descendants.

```js
'foo/' // matches 'foo/bar' and 'foo/bar/baz' etc
```

5. Regular expression syntax is supported. (except dot-all)

```js
'*.jsx?' // matches 'a.js' and 'b.jsx'
'*.(js|ts)' // matches 'a.js' and 'b.ts'
```

6. Recursive globbing is supported.

```js
'foo/**/bar' // matches 'foo/bar' and 'foo/a/b/c/bar' etc
```

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