Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/terkelg/tiny-glob
Super tiny and ~350% faster alternative to node-glob
https://github.com/terkelg/tiny-glob
expansion filesystem glob glob-pattern globbing pattern-matching patterns wildcard
Last synced: 10 days ago
JSON representation
Super tiny and ~350% faster alternative to node-glob
- Host: GitHub
- URL: https://github.com/terkelg/tiny-glob
- Owner: terkelg
- License: mit
- Created: 2018-04-11T05:12:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-10T06:46:04.000Z (almost 2 years ago)
- Last Synced: 2024-05-22T01:03:07.308Z (6 months ago)
- Topics: expansion, filesystem, glob, glob-pattern, globbing, pattern-matching, patterns, wildcard
- Language: JavaScript
- Homepage:
- Size: 150 KB
- Stars: 842
- Watchers: 11
- Forks: 33
- Open Issues: 31
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-crafted-nodejs - tiny-glob - Super tiny and ~350% faster alternative to node-glob (Packages / Others)
- awesome-f2e-libs - **tiny-glob** - 文件查找。 (命令行 / redux 扩展)
- awesome-fe - **tiny-glob** - 文件查找。 (命令行 / macros)
README
tiny glob
Tiny and extremely fast library to match files and folders using glob patterns.
"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".
## Install
```
npm install tiny-glob
```## Core Features
- 🔥 **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)
- 💪 **powerful:** supports advanced globbing patterns (`ExtGlob`)
- 📦 **tiny**: only ~45 LOC with 2 small dependencies
- 👫 **friendly**: simple and easy to use api
- 🎭 **cross-platform**: supports both unix and windows## Usage
```js
const glob = require('tiny-glob');(async function(){
let files = await glob('src/*/*.{js,md}');
// => [ ... ] array of matching files
})();
```## API
### glob(str, options)
Type: `function`
Returns: `Array`Return array of matching files and folders
This function is `async` and returns a promise.#### str
Type: `String`
The glob pattern to match against.
> **OBS**: Please only use forward-slashes in glob expressions. Even on [windows](#windows)#### options.cwd
Type: `String`
Default: `'.'`Change default working directory.
#### options.dot
Type: `Boolean`
Default: `false`Allow patterns to match filenames or directories that begin with a period (`.`).
#### options.absolute
Type: `Boolean`
Default: `false`Return matches as absolute paths.
#### options.filesOnly
Type: `Boolean`
Default: `false`Skip directories and return matched files only.
#### options.flush
Type: `Boolean`
Default: `false`Flush the internal cache object.
## Windows
Though 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.
This is common across many glob-based modules; see [`node-glob`](https://github.com/isaacs/node-glob#windows) for corroboration.
## Benchmarks
```
glob x 13,405 ops/sec ±1.80% (85 runs sampled)
fast-glob x 25,745 ops/sec ±2.76% (59 runs sampled)
tiny-glob x 102,658 ops/sec ±0.79% (91 runs sampled)
Fastest is tiny-glob
┌───────────┬─────────────────────────┬─────────────┬────────────────┐
│ Name │ Mean time │ Ops/sec │ Diff │
├───────────┼─────────────────────────┼─────────────┼────────────────┤
│ glob │ 0.00007459990597268128 │ 13,404.843 │ N/A │
├───────────┼─────────────────────────┼─────────────┼────────────────┤
│ fast-glob │ 0.000038842529587611705 │ 25,744.976 │ 92.06% faster │
├───────────┼─────────────────────────┼─────────────┼────────────────┤
│ tiny-glob │ 0.00000974110141018254 │ 102,657.796 │ 298.75% faster │
└───────────┴─────────────────────────┴─────────────┴────────────────┘
```## Advanced Globbing
Learn more about advanced globbing
- [Greg's Wiki](https://mywiki.wooledge.org/glob)
- [Bash Extended Globbing](https://www.linuxjournal.com/content/bash-extended-globbing)## License
MIT © [Terkel Gjervig](https://terkel.com)