# tree-match-sync

> Match files using glob patterns synchronously

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

## Install

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

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

## Links

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

## Dependencies (2)

- [minimatch](https://npm.io/package/minimatch.md) ^3.0.0
- [cross-spawn](https://npm.io/package/cross-spawn.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.2 (latest) — 2015-12-09
- 0.0.1 — 2015-11-16

## README

# tree-match-sync
> Match files using glob patterns synchronously

[![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 synchronously, matches files using glob patterns and then you can handle the result stored in a var :wink:

## Installation
```sh
$ npm install tree-match-sync
```
tree-match-sync 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-sync');

var tree = treeMatch(directory, pattern, options);

if(Object.prototype.toString.call(tree) === '[object Object]'){
  console.error(tree);
}else{
  console.log(tree);
}
```
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`.

The output may be an Array (all went good) or an Object (an error occured).

The Array contains the matched file names.

The Object has 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');

if(treeMatch.treeIsInstalled()){
  // OK, tree is installed, do something!
}else{
  // Well, tree isn't installed...
}
```
It has no arguments and returns `true`/`false`.

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

var tree = treeMatch('./test', '**/*.js');

if(Object.prototype.toString.call(tree) === '[object Object]'){
  console.error(tree);
}else{
  console.log(tree);
  // => [ 'test.js' ]
}
```
---
```javascript
var treeMatch = require('tree-match-sync');

var tree = treeMatch('./test', '**/*.js', { maxDepth: 0 });

if(Object.prototype.toString.call(tree) === '[object Object]'){
  console.error(tree);
  // => { status: 1, stderr: 'tree: Invalid level, must be greater than 0.\n' }
}else{
  console.log(tree);
}
```



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

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