Skip to content

Commit

Permalink
Update types.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Apr 10, 2019
1 parent bd27242 commit 64ce747
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import sep from 'path';

type AnymatchFn = (string:string) => boolean;
type AnymatchFn = (string) => boolean;
type AnymatchPattern = string|RegExp|AnymatchFn;
type AnymatchMatcher = AnymatchPattern|Array<AnymatchPattern>
declare function anymatch(matchers: AnymatchMatcher, testString: string, returnIndex?: boolean): boolean;
declare function anymatch(matchers: AnymatchMatcher): (testString: string, returnIndex?: boolean) => number;
declare function anymatch(matchers: AnymatchMatcher, testString: string|Array, returnIndex?: boolean): boolean;
declare function anymatch(matchers: AnymatchMatcher): (testString: string|Array, returnIndex?: boolean) => number;
export = anymatch;
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const matchPatterns = (patterns, negatedGlobs, path, returnIndex) => {

/**
* @param {AnymatchMatcher} matchers
* @param {String|Array<String>} testString
* @param {Array|string} testString
* @param {Boolean=} returnIndex
* @returns {boolean|Number|Function}
* @returns {boolean|number|Function}
*/
const anymatch = (matchers, testString, returnIndex = false) => {
if (matchers == null) {
Expand Down
30 changes: 15 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,26 @@ describe('anymatch', () => {

it('should pass extra args to function matchers', () => {
matchers.push((string, arg1, arg2) => arg1 || arg2);
assert(!anymatch(matchers, 'bar.js'), 1);
assert(!anymatch(matchers, ['bar.js', 0]), 2);
assert(anymatch(matchers, ['bar.js', true]), 3);
assert(anymatch(matchers, ['bar.js', 0, true]), 4);
assert(!anymatch(matchers, 'bar.js'), '1');
assert(!anymatch(matchers, ['bar.js', 0]), '2');
assert(anymatch(matchers, ['bar.js', true]), '3');
assert(anymatch(matchers, ['bar.js', 0, true]), '4');
// with returnIndex
assert.equal(anymatch(matchers, ['bar.js', 1], true), 4, 5);
assert.equal(anymatch(matchers, ['bar.js', 1], true), 4, '5');
// curried versions
var matchFn1 = anymatch(matchers);
var matchFn2 = anymatch(matchers[4]);
assert(!matchFn1(['bar.js', 0]), 6);
assert(!matchFn2(['bar.js', 0]), 7);
assert(matchFn1(['bar.js', true]), 8);
assert(matchFn2(['bar.js', true]), 9);
assert(matchFn1(['bar.js', 0, true]), 10);
assert(matchFn2(['bar.js', 0, true]), 11);
assert(!matchFn1(['bar.js', 0]), '6');
assert(!matchFn2(['bar.js', 0]), '7');
assert(matchFn1(['bar.js', true]), '8');
assert(matchFn2(['bar.js', true]), '9');
assert(matchFn1(['bar.js', 0, true]), '10');
assert(matchFn2(['bar.js', 0, true]), '11');
// curried with returnIndex
assert.equal(matchFn1(['bar.js', 1], true), 4, 12);
assert.equal(matchFn2(['bar.js', 1], true), 0, 13);
assert.equal(matchFn1(['bar.js', 0], true), -1, 14);
assert.equal(matchFn2(['bar.js', 0], true), -1, 15);
assert.equal(matchFn1(['bar.js', 1], true), 4, '12');
assert.equal(matchFn2(['bar.js', 1], true), 0, '13');
assert.equal(matchFn1(['bar.js', 0], true), -1, '14');
assert.equal(matchFn2(['bar.js', 0], true), -1, '15');
matchers.pop();
});
});
Expand Down

0 comments on commit 64ce747

Please sign in to comment.