find-up-glob
v1.0.0
Published
Find a file by walking up parent directories
Downloads
18
Maintainers
Readme
find-up-glob
Find a file by walking up parent directories
Installation
$ npm install --save find-up-glob
Usage
/
└── Users
└── tanhauhau
├── unicorn.png
└── foo
└── bar
├── a.js
└── b.js
└── awesome.txt
└── super.txt
var findUpGlob = require('find-up-glob');
//asynchronous using promise
findUpGlob('*.js').then(function(files){
console.log(files)
//=> ['/Users/tanhauhau/foo/bar/a.js', '/Users/tanhauhau/foo/bar/b.js']
})
//synchronous
var files = findUpGlob.sync('*.txt');
//=> ['/Users/tanhauhau/foo/awesome.txt', '/Users/tanhauhau/foo/super.txt']
API
findUpGlob(glob, [options])
Returns a promise for the array of filepath or null
.
findUpGlob.sync(glob, [options])
Returns an array of filepath or null
.
glob
Type: string
Glob pattern for filename matching, using minimatch to match
optionscwd
Type: string
Default: process.cwd()
Directory to start from.
Caveat
To match a parent folder you should use:findUpGlob('**/bar/*.js')
instead of findUpGlob('/bar/*.js')
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT