0.1.5 • Published 11 years ago

findup v0.1.5

Weekly downloads
367,174
License
-
Repository
github
Last release
11 years ago

build status

Find-up

Install

npm install -g findup

Usage

Find up a file in ancestor's dir

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

Async

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

var findup = require('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)

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

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

var findup = require('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('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 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 :)

@texttree/demo-bsa-reference-rclnpm-globfdt-react-styleguidist@infinitebrahmanuniverse/nolb-find@everything-registry/sub-chunk-1669svn-project-rootwitchvx-confwhechwhoshometfux-command-initthe-healththickshakevue-component-docsvisualtesting-adminvisualtesting-apivenus-confvalidate-commit-msg-regexpvalidate-commit-msg-smartvalidate-commit-msg-yqbvalidate-commit-msgjimmaaay-vue-styleguidist-testjson-packagekintsugi-buildljve-idestrict-requirestyle-depssran.nvimstart-starwars-libsourcejs-react-styleguidist@arve.knudsen/bankai@atakama/qtest@axelhzf/react-styleguidist-ts@aws/pdk@bitionaire/react-styleguidist@clea/cli@chalbert/react-styleguidist@bentley/webpack-tools-core@crshoverride/react-clivue-styleguidistvue-styleguidist-jimmyvue-styleguidist-vue-styleguidistvue-styleguidist2webgl-workshopuniversal-clitsdmuse-import@dvhb/webpack@dvhb/cli@duartejc/memed-react@effectfuljs/compiler@itwin/core-webpack-tools@fable/eslint-plugin-implicit-dependencies@matthieulemoine/react-styleguidist@mavenlink/react-styleguidist@kiiro/cli@jsmaestro/commit-validate@omneedia/npm-sass@sagebrush/engine-server@phoenix-plugin-registry/globexdesigns.brackets-jscs@rollup-umd/react-styleguidist@ssjs/shopstyle-node-commonmxd-command-initmxt-command-initmvn-deploy-filemya-command-vuedocmya-command-initpangu-command-installnpm-install-if-needednpm-quick-runpagedraw-clireact-native-fructose-loaderscoped-bulkrbc-clirollup-plugin-inline-postcssrctrrcfgsane-clisassdoc-webpack-loadersailfish-reloadproonregular-weaselreact-native-showcase-loadersenro-command-initnode-idenewfekeyng-cli-2nemoblanditiisngcli-task-runnernext-modal-pages-loadernimnpm-payload-testnpm-sassplatypi-clipipe-documentationspon-task-basicpolicygenius-react-styleguidistqlik-templateresolve-recursequick-plugins
0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

13 years ago

0.1.2

13 years ago

0.1.1

13 years ago

0.1.0

13 years ago