# prunes

> Delete empty subdirectories

Latest version **4.0.0** (published 2019-04-05) · ISC license · 0 weekly downloads

## Install

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

## 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 | 4.0.0 |
| Published | 2019-04-05 |
| First published | 2016-11-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sebastiaan Deckers |
| Maintainers | seb |
| Keywords | rm, rmdir, delete, clean, directories, folders |

## Links

- npm: https://www.npmjs.com/package/prunes
- Repository: https://gitlab.com/sebdeckers/prunes
- Homepage: https://gitlab.com/sebdeckers/prunes#readme
- Issues: https://gitlab.com/sebdeckers/prunes/issues
- npm.io page: https://npm.io/package/prunes

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2019-04-05
- 3.0.2 — 2016-11-15
- 3.0.1 — 2016-11-15
- 3.0.0 — 2016-11-15

## README

# prunes

Cleans up empty subdirectories by removing them depth-first until files are found.

This is useful when removing lots of files leaves behind the clutter of empty subdirectories.

Some implementations scan a given directory for empty subdirectories. That's fine in certain use cases but limits use to a single root directory, and requires scanning the entire subtree, which may be costly in terms of I/O operations.

prunes works the other way around: Giving it a list of directories, nested or not. It scans only the directories from the list that could potentially be empty, deleting them until a non empty ancestor directory is found. This is just as accurate but much more efficient than an exhaustive search.

## API

### `prunes(...directories)`

Cleans up empty directories, travelling up the tree until a non-empty directory is encountered. Leaves intact any files or non-empty directories.

#### directories

One or more paths of directories to prune. Each will be resolved based on the current working directory.

## Use Case

```js
import {basedir} from 'path'
import prunes from 'prunes'

const files = [
  '/some/removed/file.txt',
  '/some/removed/other/file.txt',
  '/more/deprecated/files.txt',
  '/more/deprecated/unused/files.txt',
  '/more/old/files.txt'
  // ... lots more files that were unlinked ...
]

const directories = files.map((file) => basedir(file))

prunes(directories)
```

## Example

Given
```
beep
├── ity.js
└─┬ boop
  ├─┬ o_O
  │ ├─┬ oh
  │ │ ├── hello
  │ │ └── puny
  │ └── human.txt
  └── party
```

Running
```js
prunes(
  'beep/party',
  'beep/boop/o_O/oh/hello',
  'beep/boop/o_O/oh/puny'
)
```

Produces
```
beep
├── ity.js
└─┬ boop
  └─┬ o_O
    └── human.txt
```

## Peer Dependencies

This package uses Babel to transpile its code to be compatible with the node version it is installed on. Ensure you have installed the necessary peer dependencies.

```
npm install babel-cli babel-preset-env
```

On some older Node environments, e.g. 4.x and earlier, you may also require system-wide polyfills.

```
npm install babel-polyfill
```

And then load the `babel-polyfill` library before loading this package.

## Colophon

Made by Sebastiaan Deckers in Singapore 🇸🇬

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