Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivansanchez/sandermatch
:open_file_folder: Filesystem functions that return filenames matching a minimatch pattern
https://github.com/ivansanchez/sandermatch
Last synced: about 2 months ago
JSON representation
:open_file_folder: Filesystem functions that return filenames matching a minimatch pattern
- Host: GitHub
- URL: https://github.com/ivansanchez/sandermatch
- Owner: IvanSanchez
- Created: 2016-01-14T14:29:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-22T15:58:07.000Z (almost 9 years ago)
- Last Synced: 2024-11-16T09:08:13.317Z (about 2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sandermatch
Filesystem functions that return filenames matching a minimatch pattern
## What
`sandermatch` is a small javascript library that combines the Promise-based power of [`sander`](https://github.com/Rich-Harris/sander) with the regexp-matching power of [`minimatch`](https://github.com/isaacs/minimatch).
## How
"Give me all the filenames of all PNG images in /tmp, recursively"
```js
var sandermatch = require('sandermatch');sandermatch.lsrMatch('/tmp', '**/*.png').then(function(filenames){ console.log(filenames) });
```The following functions are exported:
* `lsrMatch(...paths, patterns)`
* `lsrMatchSync(...paths, patterns)`
* `readdirMatch(...paths, patterns)`
* `readdirMatchSync(...paths, patterns)`All of them have behaviour like their counterparts in [`sander`](https://github.com/Rich-Harris/sander), but the return value is not a Promise of an array with all files. Instead, it's a Promise of a Set with the filenames that match one of `patterns`.
The resulting Set is ordered by the order of `patterns`, for example:
```
sandermatch.lsrMatch('.', ['**/*.js', '**/*.png']).then( function (filenames){
// filenames has all the *.js before any of the *.png files, e.g.
// - foo.js
// - bar.js
// - lib/whatever/whatever.js
// - logo.png
// - lib/whatever/assets/whatever.png
} );
```## Compatibility
`sandermatch` is coded in ES2016, and transpiles to ES5 **but** it assumes that the `Set` datatype exists. Since this is [implemented in node 0.12 onwards](http://kangax.github.io/compat-table/es6/#test-Set), it shouldn't be a problem.
Run `npm install` to transpile to ES5. ES5/ES2015 dependencies should be handled transparently via the `main`/`jsnext:main` properties of `package.json`.
In ES2015 packages:
```js
import { lsrMatch } from 'sandermatch';
lsrMatch(path, pattern).then(doStuff);
```