Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 18, 2021
1 parent 108cd25 commit d841a69
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 39 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
13 changes: 5 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import {IOptions} from 'minimatch';

declare namespace multimatch {
type Options = Readonly<IOptions>;
}
export 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 paths - The paths to match against.
@param patterns - Globbing patterns to use. For example: `['*', '!cake']`. See supported [`minimatch` patterns](https://github.com/isaacs/minimatch#usage).
@returns The matching paths in the order of input paths.
@example
```
import multimatch = require('multimatch');
import multimatch from 'multimatch';
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']);
//=> ['unicorn', 'rainbows']
```
*/
declare function multimatch(
export default function multimatch(
paths: string | readonly string[],
patterns: string | readonly string[],
options?: multimatch.Options
options?: Options
): string[];

export = multimatch;
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';
const minimatch = require('minimatch');
const arrayUnion = require('array-union');
const arrayDiffer = require('array-differ');
const arrify = require('arrify');
import minimatch from 'minimatch';
import arrayUnion from 'array-union';
import arrayDiffer from 'array-differ';

module.exports = (list, patterns, options = {}) => {
list = arrify(list);
patterns = arrify(patterns);
export default function multimatch(list, patterns, options = {}) {
list = [list].flat();
patterns = [patterns].flat();

if (list.length === 0 || patterns.length === 0) {
return [];
Expand All @@ -27,4 +25,4 @@ module.exports = (list, patterns, options = {}) => {
}

return result;
};
}
6 changes: 3 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import multimatch = require('.');
import multimatch, {Options} from './index.js';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options: multimatch.Options = {};
const options: Options = {};

multimatch(['unicorn', 'cake', 'rainbows'], '!cake');
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']);
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake'], {
debug: true
debug: true,
});
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -34,15 +36,14 @@
"wildcard"
],
"dependencies": {
"@types/minimatch": "^3.0.3",
"array-differ": "^3.0.0",
"array-union": "^2.1.0",
"arrify": "^2.0.1",
"@types/minimatch": "^3.0.5",
"array-differ": "^4.0.0",
"array-union": "^3.0.1",
"minimatch": "^3.0.4"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.33.1"
"ava": "^3.15.0",
"tsd": "^0.18.0",
"xo": "^0.45.0"
}
}
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
## Install

```
$ npm install multimatch
```sh
npm install multimatch
```

## Usage

```js
const multimatch = require('multimatch');
import multimatch from 'multimatch';

multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']);
//=> ['unicorn', 'rainbows']
Expand All @@ -29,7 +29,7 @@ Returns an array of matching paths in the order of input paths.

Type: `string | string[]`

Paths to match against.
The paths to match against.

#### patterns

Expand All @@ -50,7 +50,7 @@ See the [`minimatch` options](https://github.com/isaacs/minimatch#options).

Positive patterns (e.g. `foo` or `*`) add to the results, while negative patterns (e.g. `!foo`) subtract from the results.

Therefore a lone negation (e.g. `['!foo']`) will never match anything – use `['*', '!foo']` instead.
Therefore a lone negation (e.g. `['!foo']`) will never match anything. Use `['*', '!foo']` instead.

## Globbing patterns

Expand Down
2 changes: 1 addition & 1 deletion test/globule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Tests from [globule](https://github.com/cowboy/node-globule)
import test from 'ava';
import multimatch from '..';
import multimatch from '../index.js';

test('Should return empty set if a required argument is missing or an empty set.', t => {
t.deepEqual(multimatch('', 'foo.js'), []);
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import multimatch from '..';
import multimatch from '../index.js';

const fixtures = ['vendor/js/foo.js', 'vendor/js/bar.js', 'vendor/js/baz.js'];

Expand Down

0 comments on commit d841a69

Please sign in to comment.