1 | <p align="center">
|
2 | <img src="https://github.com/terkelg/tiny-glob/raw/master/tiny-glob.png" alt="Tiny Glob" width="450" height="288" />
|
3 | </p>
|
4 |
|
5 | <h1 align="center">tiny glob</h1>
|
6 |
|
7 | <p align="center">
|
8 | <a href="https://npmjs.org/package/tiny-glob">
|
9 | <img src="https://img.shields.io/npm/v/tiny-glob.svg" alt="version" />
|
10 | </a>
|
11 | <a href="https://travis-ci.org/terkelg/tiny-glob">
|
12 | <img src="https://img.shields.io/travis/terkelg/tiny-glob.svg" alt="travis" />
|
13 | </a>
|
14 | <a href="https://npmjs.org/package/tiny-glob">
|
15 | <img src="https://img.shields.io/npm/dm/tiny-glob.svg" alt="downloads" />
|
16 | </a>
|
17 | </p>
|
18 |
|
19 | <p align="center"><b>Tiny and extremely fast library to matche files and folders using glob patterns.</b></p>
|
20 |
|
21 | <br />
|
22 |
|
23 |
|
24 | "Globs" is the common name for a specific type of pattern used to match files and folders. It's the patterns you type when you do stuff like `ls *.js` in your shell or put `src/*` in a `.gitignore` file. When used to match filenames, it's sometimes called a "wildcard".
|
25 |
|
26 |
|
27 | ## Install
|
28 |
|
29 | ```
|
30 | npm install tiny-glob
|
31 | ```
|
32 |
|
33 |
|
34 | ## Core Features
|
35 |
|
36 | - 🔥 **extremely fast:** ~350% faster than [node-glob](https://github.com/isaacs/node-glob) and ~230% faster than [fast-glob](https://github.com/mrmlnc/fast-glob)
|
37 | - 💪 **powerful:** supports advanced globbing patterns (`ExtGlob`)
|
38 | - 📦 **tiny**: only ~70 LOC with only 2 small dependencies
|
39 | - 👫 **friendly**: simple and easy to use api
|
40 |
|
41 |
|
42 | ## Usage
|
43 |
|
44 | ```js
|
45 | const glob = require('tiny-glob');
|
46 |
|
47 | (async function(){
|
48 | let files = await glob('src/*/*.{js,md}');
|
49 | // => [ ... ] array of matching files
|
50 | })();
|
51 | ```
|
52 |
|
53 |
|
54 | ## API
|
55 |
|
56 |
|
57 | ### glob(str, options)
|
58 |
|
59 | Type: `function`<br>
|
60 | Returns: `Array`
|
61 |
|
62 | Return array of matching files and folders
|
63 | This function is `async` and returns a promise.
|
64 |
|
65 | #### str
|
66 |
|
67 | Type: `String`
|
68 |
|
69 | The glob pattern to match against.
|
70 |
|
71 | #### options.cwd
|
72 |
|
73 | Type: `String`<br>
|
74 | Default: `'.'`
|
75 |
|
76 | Change default working directory.
|
77 |
|
78 | #### options.dot
|
79 |
|
80 | Type: `Boolean`<br>
|
81 | Default: `false`
|
82 |
|
83 | Allow patterns to match filenames or directories that begin with a period (`.`).
|
84 |
|
85 | #### options.absolute
|
86 |
|
87 | Type: `Boolean`<br>
|
88 | Default: `false`
|
89 |
|
90 | Return matches as absolute paths.
|
91 |
|
92 | #### options.filesOnly
|
93 |
|
94 | Type: `Boolean`<br>
|
95 | Default: `false`
|
96 |
|
97 | Skip directories and return matched files only.
|
98 |
|
99 | #### options.flush
|
100 |
|
101 | Type: `Boolean`<br>
|
102 | Default: `false`
|
103 |
|
104 | Flush the internal cache object.
|
105 |
|
106 |
|
107 | ## Benchmarks
|
108 |
|
109 | ```
|
110 | glob x 13,405 ops/sec ±1.80% (85 runs sampled)
|
111 | fast-glob x 25,745 ops/sec ±2.76% (59 runs sampled)
|
112 | tiny-glob x 102,658 ops/sec ±0.79% (91 runs sampled)
|
113 | Fastest is tiny-glob
|
114 | ┌───────────┬─────────────────────────┬─────────────┬────────────────┐
|
115 | │ Name │ Mean time │ Ops/sec │ Diff │
|
116 | ├───────────┼─────────────────────────┼─────────────┼────────────────┤
|
117 | │ glob │ 0.00007459990597268128 │ 13,404.843 │ N/A │
|
118 | ├───────────┼─────────────────────────┼─────────────┼────────────────┤
|
119 | │ fast-glob │ 0.000038842529587611705 │ 25,744.976 │ 92.06% faster │
|
120 | ├───────────┼─────────────────────────┼─────────────┼────────────────┤
|
121 | │ tiny-glob │ 0.00000974110141018254 │ 102,657.796 │ 298.75% faster │
|
122 | └───────────┴─────────────────────────┴─────────────┴────────────────┘
|
123 | ```
|
124 |
|
125 | ## Advanced Globbing
|
126 |
|
127 | Learn more about advanced globbing
|
128 |
|
129 | - [Greg's Wiki](https://mywiki.wooledge.org/glob)
|
130 | - [Bash Extended Globbing](https://www.linuxjournal.com/content/bash-extended-globbing)
|
131 |
|
132 |
|
133 | ## License
|
134 |
|
135 | MIT © [Terkel Gjervig](https://terkel.com)
|