UNPKG

5.03 kBMarkdownView Raw
1<p align="center">
2 <img src="https://github.com/terkelg/tiny-glob/raw/master/tiny-glob.png" alt="Tiny Glob" width="450" />
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://ci.appveyor.com/project/terkelg/tiny-glob/branch/master">
15 <img src="https://ci.appveyor.com/api/projects/status/qe8sm2c7mwm0hxud/branch/master?svg=true" alt="AppVeyor"/>
16 </a>
17 <a href="https://npmjs.org/package/tiny-glob">
18 <img src="https://img.shields.io/npm/dm/tiny-glob.svg" alt="downloads" />
19 </a>
20 <a href="https://packagephobia.now.sh/result?p=tiny-glob">
21 <img src="https://packagephobia.now.sh/badge?p=tiny-glob" alt="install size" />
22 </a>
23</p>
24
25<p align="center"><b>Tiny and extremely fast library to match files and folders using glob patterns.</b></p>
26
27<br />
28
29
30"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".
31
32
33## Install
34
35```
36npm install tiny-glob
37```
38
39
40## Core Features
41
42- 🔥 **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)
43- 💪 **powerful:** supports advanced globbing patterns (`ExtGlob`)
44- 📦 **tiny**: only ~45 LOC with 2 small dependencies
45- 👫 **friendly**: simple and easy to use api
46- 🎭 **cross-platform**: supports both unix and windows
47
48
49## Usage
50
51```js
52const glob = require('tiny-glob');
53
54(async function(){
55 let files = await glob('src/*/*.{js,md}');
56 // => [ ... ] array of matching files
57})();
58```
59
60
61## API
62
63
64### glob(str, options)
65
66Type: `function`<br>
67Returns: `Array`
68
69Return array of matching files and folders
70This function is `async` and returns a promise.
71
72#### str
73
74Type: `String`
75
76The glob pattern to match against.
77> **OBS**: Please only use forward-slashes in glob expressions. Even on [windows](#windows)
78
79#### options.cwd
80
81Type: `String`<br>
82Default: `'.'`
83
84Change default working directory.
85
86#### options.dot
87
88Type: `Boolean`<br>
89Default: `false`
90
91Allow patterns to match filenames or directories that begin with a period (`.`).
92
93#### options.absolute
94
95Type: `Boolean`<br>
96Default: `false`
97
98Return matches as absolute paths.
99
100#### options.filesOnly
101
102Type: `Boolean`<br>
103Default: `false`
104
105Skip directories and return matched files only.
106
107#### options.flush
108
109Type: `Boolean`<br>
110Default: `false`
111
112Flush the internal cache object.
113
114
115## Windows
116
117Though Windows may use `/`, `\`, or `\\` as path separators, you can **only** use forward-slashes (`/`) when specifying glob expressions. Any back-slashes (`\`) will be interpreted as escape characters instead of path separators.
118
119This is common across many glob-based modules; see [`node-glob`](https://github.com/isaacs/node-glob#windows) for corroboration.
120
121
122## Benchmarks
123
124```
125glob x 13,405 ops/sec ±1.80% (85 runs sampled)
126fast-glob x 25,745 ops/sec ±2.76% (59 runs sampled)
127tiny-glob x 102,658 ops/sec ±0.79% (91 runs sampled)
128Fastest is tiny-glob
129┌───────────┬─────────────────────────┬─────────────┬────────────────┐
130│ Name │ Mean time │ Ops/sec │ Diff │
131├───────────┼─────────────────────────┼─────────────┼────────────────┤
132│ glob │ 0.00007459990597268128 │ 13,404.843 │ N/A │
133├───────────┼─────────────────────────┼─────────────┼────────────────┤
134│ fast-glob │ 0.000038842529587611705 │ 25,744.976 │ 92.06% faster │
135├───────────┼─────────────────────────┼─────────────┼────────────────┤
136│ tiny-glob │ 0.00000974110141018254 │ 102,657.796 │ 298.75% faster │
137└───────────┴─────────────────────────┴─────────────┴────────────────┘
138```
139
140## Advanced Globbing
141
142Learn more about advanced globbing
143
144 - [Greg's Wiki](https://mywiki.wooledge.org/glob)
145 - [Bash Extended Globbing](https://www.linuxjournal.com/content/bash-extended-globbing)
146
147
148## License
149
150MIT © [Terkel Gjervig](https://terkel.com)