source: trip-planner-front/node_modules/globby/readme.md@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.3 KB
Line 
1# globby
2
3> User-friendly glob matching
4
5Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob) but adds a bunch of useful features.
6
7## Features
8
9- Promise API
10- Multiple patterns
11- Negated patterns: `['foo*', '!foobar']`
12- Expands directories: `foo` → `foo/**/*`
13- Supports `.gitignore`
14
15## Install
16
17```
18$ npm install globby
19```
20
21## Usage
22
23```
24├── unicorn
25├── cake
26└── rainbow
27```
28
29```js
30const globby = require('globby');
31
32(async () => {
33 const paths = await globby(['*', '!cake']);
34
35 console.log(paths);
36 //=> ['unicorn', 'rainbow']
37})();
38```
39
40## API
41
42Note 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()`.
43
44### globby(patterns, options?)
45
46Returns a `Promise<string[]>` of matching paths.
47
48#### patterns
49
50Type: `string | string[]`
51
52See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).
53
54#### options
55
56Type: `object`
57
58See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones below.
59
60##### expandDirectories
61
62Type: `boolean | string[] | object`\
63Default: `true`
64
65If 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:
66
67```js
68const globby = require('globby');
69
70(async () => {
71 const paths = await globby('images', {
72 expandDirectories: {
73 files: ['cat', 'unicorn', '*.jpg'],
74 extensions: ['png']
75 }
76 });
77
78 console.log(paths);
79 //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
80})();
81```
82
83Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`.
84
85##### gitignore
86
87Type: `boolean`\
88Default: `false`
89
90Respect ignore patterns in `.gitignore` files that apply to the globbed files.
91
92### globby.sync(patterns, options?)
93
94Returns `string[]` of matching paths.
95
96### globby.stream(patterns, options?)
97
98Returns a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) of matching paths.
99
100Since Node.js 10, [readable streams are iterable](https://nodejs.org/api/stream.html#stream_readable_symbol_asynciterator), so you can loop over glob matches in a [`for await...of` loop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) like this:
101
102```js
103const globby = require('globby');
104
105(async () => {
106 for await (const path of globby.stream('*.tmp')) {
107 console.log(path);
108 }
109})();
110```
111
112### globby.generateGlobTasks(patterns, options?)
113
114Returns an `object[]` in the format `{pattern: string, options: Object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
115
116Note 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.
117
118### globby.hasMagic(patterns, options?)
119
120Returns a `boolean` of whether there are any special glob characters in the `patterns`.
121
122Note that the options affect the results.
123
124This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options).
125
126### globby.gitignore(options?)
127
128Returns a `Promise<(path: string) => boolean>` indicating whether a given path is ignored via a `.gitignore` file.
129
130Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not used for the resulting filter function.
131
132```js
133const {gitignore} = require('globby');
134
135(async () => {
136 const isIgnored = await gitignore();
137 console.log(isIgnored('some/file'));
138})();
139```
140
141### globby.gitignore.sync(options?)
142
143Returns a `(path: string) => boolean` indicating whether a given path is ignored via a `.gitignore` file.
144
145Takes the same options as `globby.gitignore`.
146
147## Globbing patterns
148
149Just a quick overview.
150
151- `*` matches any number of characters, but not `/`
152- `?` matches a single character, but not `/`
153- `**` matches any number of characters, including `/`, as long as it's the only thing in a path part
154- `{}` allows for a comma-separated list of "or" expressions
155- `!` at the beginning of a pattern will negate the match
156
157[Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)
158
159## globby for enterprise
160
161Available as part of the Tidelift Subscription.
162
163The maintainers of globby and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-globby?utm_source=npm-globby&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
164
165## Related
166
167- [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem
168- [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching
169- [del](https://github.com/sindresorhus/del) - Delete files and directories
170- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
Note: See TracBrowser for help on using the repository browser.