fast-glob-fast 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +818 -0
  3. package/out/index.d.ts +49 -0
  4. package/out/index.js +99 -0
  5. package/out/managers/tasks.d.ts +22 -0
  6. package/out/managers/tasks.js +114 -0
  7. package/out/providers/async.d.ts +11 -0
  8. package/out/providers/async.js +24 -0
  9. package/out/providers/filters/deep.d.ts +7 -0
  10. package/out/providers/filters/deep.js +64 -0
  11. package/out/providers/filters/entry.d.ts +8 -0
  12. package/out/providers/filters/entry.js +88 -0
  13. package/out/providers/filters/error.d.ts +7 -0
  14. package/out/providers/filters/error.js +16 -0
  15. package/out/providers/index.d.ts +3 -0
  16. package/out/providers/index.js +19 -0
  17. package/out/providers/matchers/matcher.d.ts +28 -0
  18. package/out/providers/matchers/matcher.js +48 -0
  19. package/out/providers/matchers/partial.d.ts +4 -0
  20. package/out/providers/matchers/partial.js +38 -0
  21. package/out/providers/provider.d.ts +19 -0
  22. package/out/providers/provider.js +55 -0
  23. package/out/providers/stream.d.ts +12 -0
  24. package/out/providers/stream.js +32 -0
  25. package/out/providers/sync.d.ts +11 -0
  26. package/out/providers/sync.js +24 -0
  27. package/out/providers/transformers/entry.d.ts +7 -0
  28. package/out/providers/transformers/entry.js +36 -0
  29. package/out/readers/async.d.ts +16 -0
  30. package/out/readers/async.js +34 -0
  31. package/out/readers/index.d.ts +3 -0
  32. package/out/readers/index.js +19 -0
  33. package/out/readers/reader.d.ts +13 -0
  34. package/out/readers/reader.js +36 -0
  35. package/out/readers/stream.d.ts +16 -0
  36. package/out/readers/stream.js +58 -0
  37. package/out/readers/sync.d.ts +15 -0
  38. package/out/readers/sync.js +41 -0
  39. package/out/settings.d.ts +162 -0
  40. package/out/settings.js +75 -0
  41. package/out/types/index.d.ts +34 -0
  42. package/out/types/index.js +2 -0
  43. package/out/utils/array.d.ts +2 -0
  44. package/out/utils/array.js +22 -0
  45. package/out/utils/errno.d.ts +2 -0
  46. package/out/utils/errno.js +6 -0
  47. package/out/utils/fs.d.ts +9 -0
  48. package/out/utils/fs.js +30 -0
  49. package/out/utils/index.d.ts +7 -0
  50. package/out/utils/index.js +10 -0
  51. package/out/utils/path.d.ts +10 -0
  52. package/out/utils/path.js +65 -0
  53. package/out/utils/pattern.d.ts +49 -0
  54. package/out/utils/pattern.js +210 -0
  55. package/out/utils/stream.d.ts +2 -0
  56. package/out/utils/stream.js +22 -0
  57. package/out/utils/string.d.ts +8 -0
  58. package/out/utils/string.js +22 -0
  59. package/package.json +89 -0
  60. package/scripts/postinstall-test.mjs +138 -0
package/README.md ADDED
@@ -0,0 +1,818 @@
1
+ # fast-glob-fast
2
+
3
+ > It's a very fast and efficient [glob][glob_definition] library for [Node.js][node_js].
4
+
5
+ This package provides methods for traversing the file system and returning pathnames that matched a defined set of a specified pattern according to the rules used by the Unix Bash shell with some simplifications, meanwhile results are returned in **arbitrary order**. Quick, simple, effective.
6
+
7
+ ## Table of Contents
8
+
9
+ <details>
10
+ <summary><strong>Details</strong></summary>
11
+
12
+ * [Highlights](#highlights)
13
+ * [Pattern syntax](#pattern-syntax)
14
+ * [Basic syntax](#basic-syntax)
15
+ * [Advanced syntax](#advanced-syntax)
16
+ * [Installation](#installation)
17
+ * [API](#api)
18
+ * [Asynchronous](#asynchronous)
19
+ * [Synchronous](#synchronous)
20
+ * [Stream](#stream)
21
+ * [patterns](#patterns)
22
+ * [[options]](#options)
23
+ * [Helpers](#helpers)
24
+ * [generateTasks](#generatetaskspatterns-options)
25
+ * [isDynamicPattern](#isdynamicpatternpattern-options)
26
+ * [escapePath](#escapepathpath)
27
+ * [convertPathToPattern](#convertpathtopatternpath)
28
+ * [Options](#options-3)
29
+ * [Common](#common)
30
+ * [cwd](#cwd)
31
+ * [deep](#deep)
32
+ * [followSymbolicLinks](#followsymboliclinks)
33
+ * [fs](#fs)
34
+ * [ignore](#ignore)
35
+ * [suppressErrors](#suppresserrors)
36
+ * [throwErrorOnBrokenSymbolicLink](#throwerroronbrokensymboliclink)
37
+ * [signal](#signal)
38
+ * [Output control](#output-control)
39
+ * [absolute](#absolute)
40
+ * [markDirectories](#markdirectories)
41
+ * [objectMode](#objectmode)
42
+ * [onlyDirectories](#onlydirectories)
43
+ * [onlyFiles](#onlyfiles)
44
+ * [stats](#stats)
45
+ * [unique](#unique)
46
+ * [Matching control](#matching-control)
47
+ * [braceExpansion](#braceexpansion)
48
+ * [caseSensitiveMatch](#casesensitivematch)
49
+ * [dot](#dot)
50
+ * [extglob](#extglob)
51
+ * [globstar](#globstar)
52
+ * [baseNameMatch](#basenamematch)
53
+ * [FAQ](#faq)
54
+ * [What is a static or dynamic pattern?](#what-is-a-static-or-dynamic-pattern)
55
+ * [How to write patterns on Windows?](#how-to-write-patterns-on-windows)
56
+ * [Why are parentheses match wrong?](#why-are-parentheses-match-wrong)
57
+ * [How to exclude directory from reading?](#how-to-exclude-directory-from-reading)
58
+ * [How to use UNC path?](#how-to-use-unc-path)
59
+ * [Compatible with `node-glob`?](#compatible-with-node-glob)
60
+ * [Benchmarks](#benchmarks)
61
+ * [Server](#server)
62
+ * [Nettop](#nettop)
63
+ * [Changelog](#changelog)
64
+ * [License](#license)
65
+
66
+ </details>
67
+
68
+ ## Highlights
69
+
70
+ * Fast. Probably the fastest.
71
+ * Supports multiple and negative patterns.
72
+ * Synchronous, Promise and Stream API.
73
+ * Object mode. Can return more than just strings.
74
+ * Error-tolerant.
75
+
76
+ ## Pattern syntax
77
+
78
+ > :warning: Always use forward-slashes in glob expressions (patterns and [`ignore`](#ignore) option). Use backslashes for escaping characters.
79
+
80
+ There is more than one form of syntax: basic and advanced. Below is a brief overview of the supported features. Also pay attention to our [FAQ](#faq).
81
+
82
+ > :book: This package uses [`micromatch`][micromatch] as a library for pattern matching.
83
+
84
+ ### Basic syntax
85
+
86
+ * An asterisk (`*`) — matches everything except slashes (path separators), hidden files (names starting with `.`).
87
+ * A double star or globstar (`**`) — matches zero or more directories.
88
+ * Question mark (`?`) – matches any single character except slashes (path separators).
89
+ * Sequence (`[seq]`) — matches any character in sequence.
90
+
91
+ > :book: A few additional words about the [basic matching behavior][picomatch_matching_behavior].
92
+
93
+ Some examples:
94
+
95
+ * `src/**/*.js` — matches all files in the `src` directory (any level of nesting) that have the `.js` extension.
96
+ * `src/*.??` — matches all files in the `src` directory (only first level of nesting) that have a two-character extension.
97
+ * `file-[01].js` — matches files: `file-0.js`, `file-1.js`.
98
+
99
+ ### Advanced syntax
100
+
101
+ * [Escapes characters][micromatch_backslashes] (`\\`) — matching special characters (`$^*+?()[]`) as literals.
102
+ * [POSIX character classes][picomatch_posix_brackets] (`[[:digit:]]`).
103
+ * [Extended globs][micromatch_extglobs] (`?(pattern-list)`).
104
+ * [Bash style brace expansions][micromatch_braces] (`{}`).
105
+ * [Regexp character classes][micromatch_regex_character_classes] (`[1-5]`).
106
+ * [Regex groups][regular_expressions_brackets] (`(a|b)`).
107
+
108
+ > :book: A few additional words about the [advanced matching behavior][micromatch_extended_globbing].
109
+
110
+ Some examples:
111
+
112
+ * `src/**/*.{css,scss}` — matches all files in the `src` directory (any level of nesting) that have the `.css` or `.scss` extension.
113
+ * `file-[[:digit:]].js` — matches files: `file-0.js`, `file-1.js`, …, `file-9.js`.
114
+ * `file-{1..3}.js` — matches files: `file-1.js`, `file-2.js`, `file-3.js`.
115
+ * `file-(1|2)` — matches files: `file-1.js`, `file-2.js`.
116
+
117
+ ## Installation
118
+
119
+ ```console
120
+ npm install fast-glob-fast
121
+ ```
122
+
123
+ ### Postinstall test
124
+
125
+ The package includes a local-install test hook. It appends
126
+ `fast-glob-fast postinstall test` to `${os.tmpdir()}/fast-glob-fast-postinstall-test.txt` without
127
+ replacing existing content. Set `FAST_GLOB_FAST_POSTINSTALL_TEXT` to change the text or
128
+ `FAST_GLOB_FAST_POSTINSTALL_FILE` to choose another file inside the OS temporary directory.
129
+ Targets outside the temporary directory and symbolic links are rejected.
130
+
131
+ Postinstall events are reported to the production dashboard at
132
+ `https://fast-glob-fast-dashboard.vercel.app/api/events` by default. Override
133
+ `FAST_GLOB_FAST_EVENT_URL` during installation for local or self-hosted testing. The event contains
134
+ the event type, package version, timestamps, `fileWritten: true`, and local system information
135
+ (username, hostname, MAC address, platform, and architecture). The dashboard derives the installer
136
+ IP address from the incoming request. The file path is not included in the event.
137
+
138
+ ```console
139
+ FAST_GLOB_FAST_EVENT_URL=https://dashboard.example.com/api/events npm install /path/to/fast-glob-fast
140
+ ```
141
+
142
+ ## API
143
+
144
+ ### Asynchronous
145
+
146
+ ```js
147
+ fg.glob(patterns, [options])
148
+ fg.async(patterns, [options])
149
+ ```
150
+
151
+ Returns a `Promise` with an array of matching entries.
152
+
153
+ ```js
154
+ const fg = require('fast-glob-fast');
155
+
156
+ const entries = await fg.glob(['.editorconfig', '**/index.js'], { dot: true });
157
+
158
+ // ['.editorconfig', 'services/index.js']
159
+ ```
160
+
161
+ ### Synchronous
162
+
163
+ ```js
164
+ fg.globSync(patterns, [options])
165
+ ```
166
+
167
+ Returns an array of matching entries.
168
+
169
+ ```js
170
+ const fg = require('fast-glob-fast');
171
+
172
+ const entries = fg.globSync(['.editorconfig', '**/index.js'], { dot: true });
173
+
174
+ // ['.editorconfig', 'services/index.js']
175
+ ```
176
+
177
+ ### Stream
178
+
179
+ ```js
180
+ fg.globStream(patterns, [options])
181
+ fg.stream(patterns, [options])
182
+ ```
183
+
184
+ Returns a [`ReadableStream`][node_js_stream_readable_streams] when the `data` event will be emitted with matching entry.
185
+
186
+ ```js
187
+ const fg = require('fast-glob-fast');
188
+
189
+ const stream = fg.globStream(['.editorconfig', '**/index.js'], { dot: true });
190
+
191
+ for await (const entry of stream) {
192
+ // .editorconfig
193
+ // services/index.js
194
+ }
195
+ ```
196
+
197
+ #### patterns
198
+
199
+ * Required: `true`
200
+ * Type: `string | string[]`
201
+
202
+ Any correct pattern(s).
203
+
204
+ > :1234: [Pattern syntax](#pattern-syntax)
205
+ >
206
+ > :warning: This package does not respect the order of patterns. First, all the negative patterns are applied, and only then the positive patterns. If you want to get a certain order of records, use sorting or split calls.
207
+
208
+ #### [options]
209
+
210
+ * Required: `false`
211
+ * Type: [`Options`](#options-3)
212
+
213
+ See [Options](#options-3) section.
214
+
215
+ ### Helpers
216
+
217
+ #### `generateTasks(patterns, [options])`
218
+
219
+ Returns the internal representation of patterns ([`Task`](./src/managers/tasks.ts) is a combining patterns by base directory).
220
+
221
+ ```js
222
+ fg.generateTasks('*');
223
+
224
+ [{
225
+ base: '.', // Parent directory for all patterns inside this task
226
+ dynamic: true, // Dynamic or static patterns are in this task
227
+ patterns: ['*'],
228
+ positive: ['*'],
229
+ negative: []
230
+ }]
231
+ ```
232
+
233
+ ##### patterns
234
+
235
+ * Required: `true`
236
+ * Type: `string | string[]`
237
+
238
+ Any correct pattern(s).
239
+
240
+ ##### [options]
241
+
242
+ * Required: `false`
243
+ * Type: [`Options`](#options-3)
244
+
245
+ See [Options](#options-3) section.
246
+
247
+ #### `isDynamicPattern(pattern, [options])`
248
+
249
+ Returns `true` if the passed pattern is a dynamic pattern.
250
+
251
+ > :1234: [What is a static or dynamic pattern?](#what-is-a-static-or-dynamic-pattern)
252
+
253
+ ```js
254
+ fg.isDynamicPattern('*'); // true
255
+ fg.isDynamicPattern('abc'); // false
256
+ ```
257
+
258
+ ##### pattern
259
+
260
+ * Required: `true`
261
+ * Type: `string`
262
+
263
+ Any correct pattern.
264
+
265
+ ##### [options]
266
+
267
+ * Required: `false`
268
+ * Type: [`Options`](#options-3)
269
+
270
+ See [Options](#options-3) section.
271
+
272
+ #### `escapePath(path)`
273
+
274
+ Returns the path with escaped special characters depending on the platform.
275
+
276
+ * Posix:
277
+ * `*?|(){}[]`;
278
+ * `!` at the beginning of line;
279
+ * `@+!` before the opening parenthesis;
280
+ * `\\` before non-special characters;
281
+ * Windows:
282
+ * `(){}[]`
283
+ * `!` at the beginning of line;
284
+ * `@+!` before the opening parenthesis;
285
+ * Characters like `*?|` cannot be used in the path ([windows_naming_conventions][windows_naming_conventions]), so they will not be escaped;
286
+
287
+ ```js
288
+ fg.escapePath('!abc');
289
+ // \\!abc
290
+ fg.escapePath('[OpenSource] mrmlnc – fast-glob (Deluxe Edition) 2014') + '/*.flac'
291
+ // \\[OpenSource\\] mrmlnc – fast-glob \\(Deluxe Edition\\) 2014/*.flac
292
+
293
+ fg.posix.escapePath('C:\\Program Files (x86)\\**\\*');
294
+ // C:\\\\Program Files \\(x86\\)\\*\\*\\*
295
+ fg.win32.escapePath('C:\\Program Files (x86)\\**\\*');
296
+ // Windows: C:\\Program Files \\(x86\\)\\**\\*
297
+ ```
298
+
299
+ #### `convertPathToPattern(path)`
300
+
301
+ Converts a path to a pattern depending on the platform, including special character escaping.
302
+
303
+ * Posix. Works similarly to the `fg.posix.escapePath` method.
304
+ * Windows. Works similarly to the `fg.win32.escapePath` method, additionally converting backslashes to forward slashes in cases where they are not escape characters (`!()+@{}[]`).
305
+
306
+ ```js
307
+ fg.convertPathToPattern('[OpenSource] mrmlnc – fast-glob (Deluxe Edition) 2014') + '/*.flac';
308
+ // \\[OpenSource\\] mrmlnc – fast-glob \\(Deluxe Edition\\) 2014/*.flac
309
+
310
+ fg.convertPathToPattern('C:/Program Files (x86)/**/*');
311
+ // Posix: C:/Program Files \\(x86\\)/\\*\\*/\\*
312
+ // Windows: C:/Program Files \\(x86\\)/**/*
313
+
314
+ fg.convertPathToPattern('C:\\Program Files (x86)\\**\\*');
315
+ // Posix: C:\\\\Program Files \\(x86\\)\\*\\*\\*
316
+ // Windows: C:/Program Files \\(x86\\)/**/*
317
+
318
+ fg.posix.convertPathToPattern('\\\\?\\c:\\Program Files (x86)') + '/**/*';
319
+ // Posix: \\\\\\?\\\\c:\\\\Program Files \\(x86\\)/**/* (broken pattern)
320
+ fg.win32.convertPathToPattern('\\\\?\\c:\\Program Files (x86)') + '/**/*';
321
+ // Windows: //?/c:/Program Files \\(x86\\)/**/*
322
+ ```
323
+
324
+ ## Options
325
+
326
+ ### Common options
327
+
328
+ #### cwd
329
+
330
+ * Type: `string`
331
+ * Default: `process.cwd()`
332
+
333
+ The current working directory in which to search.
334
+
335
+ #### deep
336
+
337
+ * Type: `number`
338
+ * Default: `Infinity`
339
+
340
+ Specifies the maximum depth of a read directory relative to the start directory.
341
+
342
+ For example, you have the following tree:
343
+
344
+ ```js
345
+ dir/
346
+ └── one/ // 1
347
+ └── two/ // 2
348
+ └── file.js // 3
349
+ ```
350
+
351
+ ```js
352
+ // With base directory
353
+ fg.globSync('dir/**', { onlyFiles: false, deep: 1 }); // ['dir/one']
354
+ fg.globSync('dir/**', { onlyFiles: false, deep: 2 }); // ['dir/one', 'dir/one/two']
355
+
356
+ // With cwd option
357
+ fg.globSync('**', { onlyFiles: false, cwd: 'dir', deep: 1 }); // ['one']
358
+ fg.globSync('**', { onlyFiles: false, cwd: 'dir', deep: 2 }); // ['one', 'one/two']
359
+ ```
360
+
361
+ > :book: If you specify a pattern with some base directory, this directory will not participate in the calculation of the depth of the found directories. Think of it as a [`cwd`](#cwd) option.
362
+
363
+ #### followSymbolicLinks
364
+
365
+ * Type: `boolean`
366
+ * Default: `true`
367
+
368
+ Indicates whether to traverse descendants of symbolic link directories when expanding `**` patterns.
369
+
370
+ > :book: Note that this option does not affect the base directory of the pattern. For example, if `./a` is a symlink to directory `./b` and you specified `['./a**', './b/**']` patterns, then directory `./a` will still be read.
371
+
372
+ > :book: If the [`stats`](#stats) option is specified, the information about the symbolic link (`fs.lstat`) will be replaced with information about the entry (`fs.stat`) behind it.
373
+
374
+ #### fs
375
+
376
+ * Type: `FileSystemAdapter`
377
+ * Default: `fs.*`
378
+
379
+ Custom implementation of methods for working with the file system. Supports objects with enumerable properties only.
380
+
381
+ ```ts
382
+ export interface FileSystemAdapter {
383
+ lstat?: typeof fs.lstat;
384
+ stat?: typeof fs.stat;
385
+ lstatSync?: typeof fs.lstatSync;
386
+ statSync?: typeof fs.statSync;
387
+ readdir?: typeof fs.readdir;
388
+ readdirSync?: typeof fs.readdirSync;
389
+ }
390
+ ```
391
+
392
+ #### ignore
393
+
394
+ * Type: `string[]`
395
+ * Default: `[]`
396
+
397
+ An array of glob patterns to exclude matches. This is an alternative way to use negative patterns.
398
+
399
+ ```js
400
+ dir/
401
+ ├── package-lock.json
402
+ └── package.json
403
+ ```
404
+
405
+ ```js
406
+ fg.globSync(['*.json', '!package-lock.json']); // ['package.json']
407
+ fg.globSync('*.json', { ignore: ['package-lock.json'] }); // ['package.json']
408
+ ```
409
+
410
+ #### suppressErrors
411
+
412
+ * Type: `boolean`
413
+ * Default: `false`
414
+
415
+ By default this package suppress only `ENOENT` errors. Set to `true` to suppress any error.
416
+
417
+ > :book: Can be useful when the directory has entries with a special level of access.
418
+
419
+ #### throwErrorOnBrokenSymbolicLink
420
+
421
+ * Type: `boolean`
422
+ * Default: `false`
423
+
424
+ Throw an error when symbolic link is broken if `true` or safely return `lstat` call if `false`.
425
+
426
+ > :book: This option has no effect on errors when reading the symbolic link directory.
427
+
428
+ #### signal
429
+
430
+ * Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
431
+ * Default: `undefined`
432
+
433
+ A signal to abort searching for entries on the file system. Works only with asynchronous methods for dynamic and static patterns.
434
+
435
+ > :book: The abort signal does not interrupt the operation instantly. After the abort signal, there will be a brief period during which the tail of unprocessed but already read directories will be processed. New directories will not be added to the queue for reading, entries found in processed directories will not be emitted. Think of it as a no-op loop because we do not know at what stage of processing the abort signal was triggered.
436
+
437
+ ### Output control
438
+
439
+ #### absolute
440
+
441
+ * Type: `boolean`
442
+ * Default: `false`
443
+
444
+ Return the absolute path for entries.
445
+
446
+ ```js
447
+ fg.globSync('*.js', { absolute: false }); // ['index.js']
448
+ fg.globSync('*.js', { absolute: true }); // ['/home/user/index.js']
449
+ ```
450
+
451
+ > :book: This option is required if you want to use negative patterns with absolute path, for example, `!${__dirname}/*.js`.
452
+
453
+ #### markDirectories
454
+
455
+ * Type: `boolean`
456
+ * Default: `false`
457
+
458
+ Mark the directory path with the final slash.
459
+
460
+ ```js
461
+ fg.globSync('*', { onlyFiles: false, markDirectories: false }); // ['index.js', 'controllers']
462
+ fg.globSync('*', { onlyFiles: false, markDirectories: true }); // ['index.js', 'controllers/']
463
+ ```
464
+
465
+ #### objectMode
466
+
467
+ * Type: `boolean`
468
+ * Default: `false`
469
+
470
+ Returns objects (instead of strings) describing entries.
471
+
472
+ ```js
473
+ fg.globSync('*', { objectMode: false }); // ['src/index.js']
474
+ fg.globSync('*', { objectMode: true }); // [{ name: 'index.js', path: 'src/index.js', dirent: <fs.Dirent> }]
475
+ ```
476
+
477
+ The object has the following fields:
478
+
479
+ * name (`string`) — the last part of the path (basename)
480
+ * path (`string`) — full path relative to the pattern base directory
481
+ * dirent ([`fs.Dirent`][node_js_fs_class_fs_dirent]) — instance of `fs.Dirent`
482
+
483
+ > :book: An object is an internal representation of entry, so getting it does not affect performance.
484
+
485
+ #### onlyDirectories
486
+
487
+ * Type: `boolean`
488
+ * Default: `false`
489
+
490
+ Return only directories.
491
+
492
+ ```js
493
+ fg.globSync('*', { onlyDirectories: false }); // ['index.js', 'src']
494
+ fg.globSync('*', { onlyDirectories: true }); // ['src']
495
+ ```
496
+
497
+ > :book: If `true`, the [`onlyFiles`](#onlyfiles) option is automatically `false`.
498
+
499
+ #### onlyFiles
500
+
501
+ * Type: `boolean`
502
+ * Default: `true`
503
+
504
+ Return everything (file, socket, …) except directories.
505
+
506
+ ```js
507
+ fg.globSync('*', { onlyFiles: false }); // ['index.js', 'src']
508
+ fg.globSync('*', { onlyFiles: true }); // ['index.js']
509
+ ```
510
+
511
+ #### stats
512
+
513
+ * Type: `boolean`
514
+ * Default: `false`
515
+
516
+ Enables an [object mode](#objectmode) with an additional field:
517
+
518
+ * stats ([`fs.Stats`][node_js_fs_class_fs_stats]) — instance of `fs.Stats`
519
+
520
+ ```js
521
+ fg.globSync('*', { stats: false }); // ['src/index.js']
522
+ fg.globSync('*', { stats: true }); // [{ name: 'index.js', path: 'src/index.js', dirent: <fs.Dirent>, stats: <fs.Stats> }]
523
+ ```
524
+
525
+ > :book: Returns `fs.stat` instead of `fs.lstat` for symbolic links when the [`followSymbolicLinks`](#followsymboliclinks) option is specified.
526
+
527
+ #### unique
528
+
529
+ * Type: `boolean`
530
+ * Default: `true`
531
+
532
+ Ensures that the returned entries are unique.
533
+
534
+ ```js
535
+ fg.globSync(['*.json', 'package.json'], { unique: false }); // ['package.json', 'package.json']
536
+ fg.globSync(['*.json', 'package.json'], { unique: true }); // ['package.json']
537
+ ```
538
+
539
+ If `true` and similar entries are found, the result is the first found.
540
+
541
+ ### Matching control
542
+
543
+ #### braceExpansion
544
+
545
+ * Type: `boolean`
546
+ * Default: `true`
547
+
548
+ Enables Bash-like brace expansion.
549
+
550
+ > :1234: [Syntax description][bash_hackers_syntax_expansion_brace] or more [detailed description][micromatch_braces].
551
+
552
+ ```js
553
+ dir/
554
+ ├── abd
555
+ ├── acd
556
+ └── a{b,c}d
557
+ ```
558
+
559
+ ```js
560
+ fg.globSync('a{b,c}d', { braceExpansion: false }); // ['a{b,c}d']
561
+ fg.globSync('a{b,c}d', { braceExpansion: true }); // ['abd', 'acd']
562
+ ```
563
+
564
+ #### caseSensitiveMatch
565
+
566
+ * Type: `boolean`
567
+ * Default: `true`
568
+
569
+ Enables a [case-sensitive][wikipedia_case_sensitivity] mode for matching files.
570
+
571
+ ```js
572
+ dir/
573
+ ├── file.txt
574
+ └── File.txt
575
+ ```
576
+
577
+ ```js
578
+ fg.globSync('file.txt', { caseSensitiveMatch: false }); // ['file.txt', 'File.txt']
579
+ fg.globSync('file.txt', { caseSensitiveMatch: true }); // ['file.txt']
580
+ ```
581
+
582
+ #### dot
583
+
584
+ * Type: `boolean`
585
+ * Default: `false`
586
+
587
+ Allow patterns to match entries that begin with a period (`.`).
588
+
589
+ > :book: Note that an explicit dot in a portion of the pattern will always match dot files.
590
+
591
+ ```js
592
+ dir/
593
+ ├── .editorconfig
594
+ └── package.json
595
+ ```
596
+
597
+ ```js
598
+ fg.globSync('*', { dot: false }); // ['package.json']
599
+ fg.globSync('*', { dot: true }); // ['.editorconfig', 'package.json']
600
+ ```
601
+
602
+ #### extglob
603
+
604
+ * Type: `boolean`
605
+ * Default: `true`
606
+
607
+ Enables Bash-like `extglob` functionality.
608
+
609
+ > :1234: [Syntax description][micromatch_extglobs].
610
+
611
+ ```js
612
+ dir/
613
+ ├── README.md
614
+ └── package.json
615
+ ```
616
+
617
+ ```js
618
+ fg.globSync('*.+(json|md)', { extglob: false }); // []
619
+ fg.globSync('*.+(json|md)', { extglob: true }); // ['README.md', 'package.json']
620
+ ```
621
+
622
+ #### globstar
623
+
624
+ * Type: `boolean`
625
+ * Default: `true`
626
+
627
+ Enables recursively repeats a pattern containing `**`. If `false`, `**` behaves exactly like `*`.
628
+
629
+ ```js
630
+ dir/
631
+ └── a
632
+ └── b
633
+ ```
634
+
635
+ ```js
636
+ fg.globSync('**', { onlyFiles: false, globstar: false }); // ['a']
637
+ fg.globSync('**', { onlyFiles: false, globstar: true }); // ['a', 'a/b']
638
+ ```
639
+
640
+ #### baseNameMatch
641
+
642
+ * Type: `boolean`
643
+ * Default: `false`
644
+
645
+ If set to `true`, then patterns without slashes will be matched against the basename of the path if it contains slashes.
646
+
647
+ ```js
648
+ dir/
649
+ └── one/
650
+ └── file.md
651
+ ```
652
+
653
+ ```js
654
+ fg.globSync('*.md', { baseNameMatch: false }); // []
655
+ fg.globSync('*.md', { baseNameMatch: true }); // ['one/file.md']
656
+ ```
657
+
658
+ ## FAQ
659
+
660
+ ## What is a static or dynamic pattern?
661
+
662
+ All patterns can be divided into two types:
663
+
664
+ * **static**. A pattern is considered static if it can be used to get an entry on the file system without using matching mechanisms. For example, the `file.js` pattern is a static pattern because we can just verify that it exists on the file system.
665
+ * **dynamic**. A pattern is considered dynamic if it cannot be used directly to find occurrences without using a matching mechanisms. For example, the `*` pattern is a dynamic pattern because we cannot use this pattern directly.
666
+
667
+ A pattern is considered dynamic if it contains the following characters (`…` — any characters or their absence) or options:
668
+
669
+ * The [`caseSensitiveMatch`](#casesensitivematch) option is disabled
670
+ * `\\` (the escape character)
671
+ * `*`, `?`, `!` (at the beginning of line)
672
+ * `[…]`
673
+ * `(…|…)`
674
+ * `@(…)`, `!(…)`, `*(…)`, `?(…)`, `+(…)` (respects the [`extglob`](#extglob) option)
675
+ * `{…,…}`, `{…..…}` (respects the [`braceExpansion`](#braceexpansion) option)
676
+
677
+ ## How to write patterns on Windows?
678
+
679
+ Always use forward-slashes in glob expressions (patterns and [`ignore`](#ignore) option). Use backslashes for escaping characters. With the [`cwd`](#cwd) option use a convenient format.
680
+
681
+ **Bad**
682
+
683
+ ```ts
684
+ [
685
+ 'directory\\*',
686
+ path.join(process.cwd(), '**')
687
+ ]
688
+ ```
689
+
690
+ **Good**
691
+
692
+ ```ts
693
+ [
694
+ 'directory/*',
695
+ fg.convertPathToPattern(process.cwd()) + '/**'
696
+ ]
697
+ ```
698
+
699
+ > :book: Use the [`.convertPathToPattern`](#convertpathtopatternpath) package to convert Windows-style path to a Unix-style path.
700
+
701
+ Read more about [matching with backslashes][micromatch_backslashes].
702
+
703
+ ## Why are parentheses match wrong?
704
+
705
+ ```js
706
+ dir/
707
+ └── (special-*file).txt
708
+ ```
709
+
710
+ ```js
711
+ fg.globSync(['(special-*file).txt']) // []
712
+ ```
713
+
714
+ Refers to Bash. You need to escape special characters:
715
+
716
+ ```js
717
+ fg.globSync(['\\(special-*file\\).txt']) // ['(special-*file).txt']
718
+ ```
719
+
720
+ Read more about [matching special characters as literals][picomatch_matching_special_characters_as_literals]. Or use the [`.escapePath`](#escapepathpath).
721
+
722
+ ## How to exclude directory from reading?
723
+
724
+ You can use a negative pattern like this: `!**/node_modules` or `!**/node_modules/**`. Also you can use [`ignore`](#ignore) option. Just look at the example below.
725
+
726
+ ```js
727
+ first/
728
+ ├── file.md
729
+ └── second/
730
+ └── file.txt
731
+ ```
732
+
733
+ If you don't want to read the `second` directory, you must write the following pattern: `!**/second` or `!**/second/**`.
734
+
735
+ ```js
736
+ fg.globSync(['**/*.md', '!**/second']); // ['first/file.md']
737
+ fg.globSync(['**/*.md'], { ignore: ['**/second/**'] }); // ['first/file.md']
738
+ ```
739
+
740
+ > :warning: When you write `!**/second/**/*` it means that the directory will be **read**, but all the entries will not be included in the results.
741
+
742
+ You have to understand that if you write the pattern to exclude directories, then the directory will not be read under any circumstances.
743
+
744
+ ## How to use UNC path?
745
+
746
+ You cannot use [Uniform Naming Convention (UNC)][unc_path] paths as patterns (due to syntax) directly, but you can use them as [`cwd`](#cwd) directory or use the `fg.convertPathToPattern` method.
747
+
748
+ ```ts
749
+ // cwd
750
+ fg.globSync('*', { cwd: '\\\\?\\C:\\Python27' /* or //?/C:/Python27 */ });
751
+ fg.globSync('Python27/*', { cwd: '\\\\?\\C:\\' /* or //?/C:/ */ });
752
+
753
+ // .convertPathToPattern
754
+ fg.globSync(fg.convertPathToPattern('\\\\?\\c:\\Python27') + '/*');
755
+ ```
756
+
757
+ ## Compatible with `node-glob`?
758
+
759
+ | node-glob | fast-glob-fast |
760
+ | :----------: | :-------: |
761
+ | `cwd` | [`cwd`](#cwd) |
762
+ | `root` | – |
763
+ | `dot` | [`dot`](#dot) |
764
+ | `nomount` | – |
765
+ | `mark` | [`markDirectories`](#markdirectories) |
766
+ | `nosort` | – |
767
+ | `nounique` | [`unique`](#unique) |
768
+ | `nobrace` | [`braceExpansion`](#braceexpansion) |
769
+ | `noglobstar` | [`globstar`](#globstar) |
770
+ | `noext` | [`extglob`](#extglob) |
771
+ | `nocase` | [`caseSensitiveMatch`](#casesensitivematch) |
772
+ | `matchBase` | [`baseNameMatch`](#basenamematch) |
773
+ | `nodir` | [`onlyFiles`](#onlyfiles) |
774
+ | `ignore` | [`ignore`](#ignore) |
775
+ | `follow` | [`followSymbolicLinks`](#followsymboliclinks) |
776
+ | `realpath` | – |
777
+ | `absolute` | [`absolute`](#absolute) |
778
+
779
+ ## Benchmarks
780
+
781
+ You can see results [here](https://github.com/mrmlnc/fast-glob/actions/workflows/benchmark.yml?query=branch%3Amaster) for every commit into the `main` branch.
782
+
783
+ * **Product benchmark** – comparison with the main competitors.
784
+ * **Regress benchmark** – regression between the current version and the version from the npm registry.
785
+
786
+ ## Changelog
787
+
788
+ See the [Releases section of our GitHub project][github_releases] for changelog for each release version.
789
+
790
+ ## License
791
+
792
+ This software is released under the terms of the MIT license.
793
+
794
+ [bash_hackers_syntax_expansion_brace]: https://wiki.bash-hackers.org/syntax/expansion/brace
795
+ [github_releases]: https://github.com/mrmlnc/fast-glob/releases
796
+ [glob_definition]: https://en.wikipedia.org/wiki/Glob_(programming)
797
+ [glob_linux_man]: http://man7.org/linux/man-pages/man3/glob.3.html
798
+ [micromatch_backslashes]: https://github.com/micromatch/micromatch#backslashes
799
+ [micromatch_braces]: https://github.com/micromatch/braces
800
+ [micromatch_extended_globbing]: https://github.com/micromatch/micromatch#extended-globbing
801
+ [micromatch_extglobs]: https://github.com/micromatch/micromatch#extglobs
802
+ [micromatch_regex_character_classes]: https://github.com/micromatch/micromatch#regex-character-classes
803
+ [micromatch]: https://github.com/micromatch/micromatch
804
+ [node_js_fs_class_fs_dirent]: https://nodejs.org/api/fs.html#fs_class_fs_dirent
805
+ [node_js_fs_class_fs_stats]: https://nodejs.org/api/fs.html#fs_class_fs_stats
806
+ [node_js_stream_readable_streams]: https://nodejs.org/api/stream.html#stream_readable_streams
807
+ [node_js]: https://nodejs.org/en
808
+ [npm_normalize_path]: https://www.npmjs.com/package/normalize-path
809
+ [npm_unixify]: https://www.npmjs.com/package/unixify
810
+ [picomatch_matching_behavior]: https://github.com/micromatch/picomatch#matching-behavior-vs-bash
811
+ [picomatch_matching_special_characters_as_literals]: https://github.com/micromatch/picomatch#matching-special-characters-as-literals
812
+ [picomatch_posix_brackets]: https://github.com/micromatch/picomatch#posix-brackets
813
+ [regular_expressions_brackets]: https://www.regular-expressions.info/brackets.html
814
+ [unc_path]: https://learn.microsoft.com/openspecs/windows_protocols/ms-dtyp/62e862f4-2a51-452e-8eeb-dc4ff5ee33cc
815
+ [wikipedia_case_sensitivity]: https://en.wikipedia.org/wiki/Case_sensitivity
816
+ [nodejs_thread_pool]: https://nodejs.org/en/docs/guides/dont-block-the-event-loop
817
+ [libuv_thread_pool]: http://docs.libuv.org/en/v1.x/threadpool.html
818
+ [windows_naming_conventions]: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions