# tree-match

> Match files using glob patterns

Latest version **0.0.3** (published 2015-12-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install tree-match
pnpm add tree-match
yarn add tree-match
bun add tree-match
```

## 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.0.3 |
| Published | 2015-12-09 |
| First published | 2015-11-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Raul Macarie |
| Maintainers | bored |
| Keywords | tree, match, file, glob |

## Links

- npm: https://www.npmjs.com/package/tree-match
- Repository: https://github.com/boredz/tree-match
- Homepage: https://github.com/boredz/tree-match#readme
- Issues: https://github.com/boredz/tree-match/issues
- npm.io page: https://npm.io/package/tree-match

## Dependencies (2)

- [minimatch](https://npm.io/package/minimatch.md) ^3.0.0
- [cross-spawn-async](https://npm.io/package/cross-spawn-async.md) ^2.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

- 0.0.3 (latest) — 2015-12-09
- 0.0.2 — 2015-11-16
- 0.0.1 — 2015-11-15

## README

# tree-match
> Match files using glob patterns

[![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependencies Status][dependencies-image]][dependencies-url] [![devDependencies Status][devDependencies-image]][devDependencies-url]

You don't have to use the File System API to find files, just use this module!

Under the hood it spawns a `tree` command, matches files using glob patterns and then you can handle the result with a Promise API :wink:

## Installation
```sh
$ npm install tree-match
```
tree-match depends on the `tree` command, if it's not installed run one of these commands based on your OS:

- Debian, Ubuntu (and any other `apt-get` based distro)
```sh
apt-get install tree
```
- openSUSE
```sh
zypper install tree
```
- Fedora, CentOS, RHEL (and any other `yum` or `dnf` based distro):
```sh
## Fedora <= 21, CentOS, RHEL
yum install tree
## Fedora >= 22
dnf install tree
```
- Mac OS, with [Homebrew](http://brew.sh/)
```sh
brew install tree
```
- Windows
```sh
bin\tree.exe
```
Included in the package, provided by [GnuWin32](http://gnuwin32.sourceforge.net/packages/tree.htm).

## Usage
```javascript
var treeMatch = require('tree-match');

treeMatch(directory, pattern, options)
  .then(function(output){

  }).catch(function(error){

  });
```
As you can see there are three arguments:

1. `directory`: the path of the folder that you want to search in, the current working directory is your app location;
1. `pattern`: [glob pattern](https://tr.im/glob), using [minimatch](https://github.com/isaacs/minimatch), use only its [features](https://github.com/isaacs/minimatch#features);
1. `options`: minimatch's [options](https://github.com/isaacs/minimatch#options) with an extra field, `maxDepth: int` that translates to `tree`'s option `-L level` - `Descend only level directories deep`. I recommend you to always set this field when you don't know how many files may be contained in `directory`.

`output` is an Array containing the matched file names.

`error` is an Object with two fields:

1. `status`: the exit code of `tree`;
1. `stderr`: the error message.


There's also a function that controls if the `tree` command is installed:
```javascript
var treeMatch = require('tree-match');

treeMatch.treeIsInstalled()
  .then(function(){
    // OK, tree is installed, do something!
  }).catch(function(){
    // Well, tree isn't installed...
  });
```
It has no arguments and returns nothing.

## Examples
```javascript
var treeMatch = require('tree-match');

treeMatch('./test', '**/*.js').then(function(output){
  console.log(output);
  // => [ 'test.js' ]
}).catch(function(error){
  console.error(error);
});
```
---
```javascript
var treeMatch = require('tree-match');

treeMatch('./test', '**/*.js', { maxDepth: 0 }).then(function(output){
  console.log(output);
}).catch(function(error){
  console.error(error);
  // => { status: 1, stderr: 'tree: Invalid level, must be greater than 0.\n' }
});
```



[npm-url]: https://npmjs.org/package/tree-match
[npm-image]: http://img.shields.io/npm/v/tree-match.svg
[travis-image]: https://api.travis-ci.org/boredz/tree-match.svg
[travis-url]: https://travis-ci.org/boredz/tree-match
[dependencies-url]: https://david-dm.org/boredz/tree-match/
[dependencies-image]: https://david-dm.org/boredz/tree-match.svg
[devDependencies-url]: https://david-dm.org/boredz/tree-match/#info=devDependencies
[devDependencies-image]: https://david-dm.org/boredz/tree-match/dev-status.svg

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