Recursively match files using the patterns the shell uses
- Promise API
- Multiple patterns
- Negated patterns:
['foo*', '!foobar'] - Expands directories:
foo→foo/**/* - Supports
.gitignoreand similar ignore config files
$ npm install --save @atomic-reactor/globber
├── unicorn
├── cake
└── rainbow
// Async
const globber = require('@atomic-reactor/globber');
const paths = await globber(['*', '!cake']);
console.log(paths);
//=> ['unicorn', 'rainbow']
// Sync
const globber = require('@attomic-reactor/globber');
const paths = globber.sync(['*', '!cake']);
console.log(paths);
//=> ['unicorn', 'rainbow']Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use path.posix.join() instead of path.join().
Returns a Promise<string[]> of matching paths.
Type: string | string[]
See supported minimatch patterns.
Type: object
Type: boolean
Default: true
If set to true, globby will automatically glob directories for you. If you define an Array it will only glob files that matches the patterns inside the Array. You can also define an object with files and extensions like below:
├── unicorn
├── cake
├──── chocolate.jpg
├──── yellow.jpg
└── rainbow.jpg
const globber = require('@atomic-reactor/globber');
(async () => {
const paths = await globber('images', {
expandDirectories: false,
});
console.log(paths);
//=> ['rainbow.jpg']
})();Type: boolean
Default: false
Respect ignore patterns in .gitignore files that apply to the globbed files.
Type: string[]
Default: undefined
Glob patterns to look for ignore files, which are then used to ignore globbed files.
Async version of globber.
Just a quick overview.
*matches any number of characters, but not/?matches a single character, but not/**matches any number of characters, including/, as long as it's the only thing in a path part{}allows for a comma-separated list of "or" expressions!at the beginning of a pattern will negate the match