1 # globby [![Build Status](https://travis-ci.org/sindresorhus/globby.svg?branch=master)](https://travis-ci.org/sindresorhus/globby)
3 > User-friendly glob matching
5 Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob), but adds a bunch of useful features and a nicer API.
12 - Negated patterns: `['foo*', '!foobar']`
13 - Expands directories: `dir` → `dir/**/*`
14 - Supports `.gitignore`
33 const globby = require('globby');
36 const paths = await globby(['*', '!cake']);
39 //=> ['unicorn', 'rainbow']
46 ### globby(patterns, [options])
48 Returns a `Promise<Array>` of matching paths.
52 Type: `string` `Array`
54 See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).
60 See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options) in addition to the ones below.
62 ##### expandDirectories
64 Type: `boolean` `Array` `Object`<br>
67 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:
71 const paths = await globby('images', {
73 files: ['cat', 'unicorn', '*.jpg'],
79 //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
83 Note that if you set this option to `false`, you won't get back matched directories unless you set `nodir: false`.
90 Respect ignore patterns in `.gitignore` files that apply to the globbed files.
92 ### globby.sync(patterns, [options])
94 Returns an `Array` of matching paths.
96 ### globby.generateGlobTasks(patterns, [options])
98 Returns an `Array<Object>` in the format `{pattern: string, opts: Object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
100 Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.
102 ### globby.hasMagic(patterns, [options])
104 Returns a `boolean` of whether there are any special glob characters in the `patterns`.
106 Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set.
108 This function is backed by [`node-glob`](https://github.com/isaacs/node-glob#globhasmagicpattern-options)
110 ### globby.gitignore([options])
112 Returns a `Promise<(path: string) => boolean>` indicating whether a given path is ignored via a `.gitignore` file.
114 Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not
115 used for the resulting filter function.
118 const {gitignore} = require('globby');
121 const isIgnored = await gitignore();
122 console.log(isIgnored('some/file'));
126 ### globby.gitignore.sync([options])
128 Returns a `(path: string) => boolean` indicating whether a given path is ignored via a `.gitignore` file.
130 Takes the same options as `globby.gitignore`.
135 Just a quick overview.
137 - `*` matches any number of characters, but not `/`
138 - `?` matches a single character, but not `/`
139 - `**` matches any number of characters, including `/`, as long as it's the only thing in a path part
140 - `{}` allows for a comma-separated list of "or" expressions
141 - `!` at the beginning of a pattern will negate the match
143 [Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/master/test/test.js)
148 - [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem
149 - [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching
150 - [del](https://github.com/sindresorhus/del) - Delete files and directories
151 - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
156 MIT © [Sindre Sorhus](https://sindresorhus.com)