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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@choojs/findup

v0.2.1

Published

Find a file by walking up the directory tree

Downloads

1,282,601

Readme

build status @choojs/findup

This is a fork of Filirom1/findup, pending #16.

Install

npm install -g @choojs/findup

Usage

Find up a file in ancestor's dir

.
├── config.json
└── f
    └── e
        └── d
            └── c
                ├── b
                │   └── a
                └── config.json

Options

  • maxdepth: (Number, default -1) How far to traverse before giving up. If maxdepth is -1, then there is no limit.

Async

findup(dir, fileName, options, callback) findup(dir, iterator, options, callback) with iterator(dir, cb) where cb only accept true or false

var findup = require('@choojs/findup');


findup(__dirname + '/f/e/d/c/b/a', 'config.json', function(err, dir){
  // if(e) e === new Error('not found')
  // dir === '/f/e/d/c'
});

or

findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
  require('path').exists(dir + '/config.json', cb);
}, function(err, dir){
  // if(e) e === new Error('not found')
  // dir === '/f/e/d/c'
});

EventEmitter

findup(dir, fileName, options)

var findup = require('@choojs/findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', 'config.json');

findup(dir, iterator, options) with iterator(dir, cb) where cb only accept true or false

var findup = require('@choojs/findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
  require('path').exists(dir + '/config.json', cb);
});

findup return an EventEmitter. 3 events are emitted: found, error, end

found event is emitted each time a file is found.

You can stop the traversing by calling stop manually.

fup.on('found', function(dir){
  // dir === '/f/e/d/c'
  fup.stop();
});

error event is emitted when error happens

fup.on('error', function(e){
  // if(e) e === new Error('not found')
});

end event is emitted at the end of the traversing or after stop() is called.

fup.on('end', function(){
  // happy end
});

Sync

findup(dir, fileName) findup(dir, iteratorSync) with iteratorSync return true or false

var findup = require('@choojs/findup');

try{
  var dir = findup.sync(__dirname + '/f/e/d/c/b/a', 'config.json'); // dir === '/f/e/d/c'
}catch(e){
  // if(e) e === new Error('not found')
}

CLI

npm install -g @choojs/findup

$ cd test/fixture/f/e/d/c/b/a/
$ findup package.json
/root/findup/package.json

Usage

$ findup -h

Usage: findup [FILE]

    --name, -n       The name of the file to found
    --dir, -d        The directoy where we will start walking up    $PWD
    --help, -h       show usage                                     false
    --verbose, -v    print log                                      false

LICENSE MIT

Read the tests :)