npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tree-match-sync

v0.0.2

Published

Match files using glob patterns synchronously

Readme

tree-match-sync

Match files using glob patterns synchronously

NPM Version Build Status Dependencies Status devDependencies Status

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

$ 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)
apt-get install tree
  • openSUSE
zypper install tree
  • Fedora, CentOS, RHEL (and any other yum or dnf based distro):
## Fedora <= 21, CentOS, RHEL
yum install tree
## Fedora >= 22
dnf install tree
brew install tree
  • Windows
bin\tree.exe

Included in the package, provided by GnuWin32.

Usage

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;
  2. pattern: glob pattern, using minimatch, use only its features;
  3. options: minimatch's 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;
  2. stderr: the error message.

There's also a function that controls if the tree command is installed:

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

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' ]
}

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);
}