Skip to content

Commit

Permalink
Add TypeScript definition (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 22, 2019
1 parent 3aecd8a commit 8942da8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
28 changes: 28 additions & 0 deletions index.d.ts
@@ -0,0 +1,28 @@
import {IOptions} from 'minimatch';

declare namespace multimatch {
type Options = Readonly<IOptions>;
}

/**
Extends [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) with support for multiple patterns.
@param paths - Paths to match against.
@param patterns - Globbing patterns to use. e.g. `[*, "!cake"]`. See supported [`minimatch` patterns](https://github.com/isaacs/minimatch#usage).
@returns The matching paths.
@example
```
import multimatch = require('multimatch');
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']);
//=> ['unicorn', 'rainbows']
```
*/
declare function multimatch(
paths: string | string[],
patterns: string | string[],
options?: multimatch.Options
): string[];

export = multimatch;
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -12,14 +12,14 @@ module.exports = (list, patterns, options = {}) => {
return [];
}

return patterns.reduce((ret, pattern) => {
return patterns.reduce((result, pattern) => {
let process = arrayUnion;

if (pattern[0] === '!') {
pattern = pattern.slice(1);
process = arrayDiffer;
}

return process(ret, minimatch.match(list, pattern, options));
return process(result, minimatch.match(list, pattern, options));
}, []);
};
9 changes: 9 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,9 @@
import multimatch = require('.');

const options: multimatch.Options = {};

multimatch(['unicorn', 'cake', 'rainbows'], '!cake');
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']);
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake'], {
debug: true
});
11 changes: 7 additions & 4 deletions package.json
Expand Up @@ -13,10 +13,11 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"expand",
Expand All @@ -32,13 +33,15 @@
"wildcard"
],
"dependencies": {
"@types/minimatch": "^3.0.3",
"array-differ": "^2.0.3",
"array-union": "^1.0.2",
"arrify": "^1.0.1",
"minimatch": "^3.0.4"
},
"devDependencies": {
"ava": "^1.0.1",
"xo": "^0.23.0"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
6 changes: 4 additions & 2 deletions readme.md
Expand Up @@ -32,18 +32,20 @@ Returns an array of matching paths.

Type: `string` `string[]`

Paths to match against.

#### patterns

Type: `string` `string[]`

See supported [`minimatch` patterns](https://github.com/isaacs/minimatch#usage).
Globbing patterns to use. e.g. `[*, "!cake"]`. See supported [`minimatch` patterns](https://github.com/isaacs/minimatch#usage).

- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js)
- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)

#### options

Type: `Object`
Type: `object`

See the [`minimatch` options](https://github.com/isaacs/minimatch#options).

Expand Down

0 comments on commit 8942da8

Please sign in to comment.