diff --git a/types/anymatch/anymatch-tests.ts b/types/anymatch/anymatch-tests.ts new file mode 100644 index 0000000000..3333903760 --- /dev/null +++ b/types/anymatch/anymatch-tests.ts @@ -0,0 +1,43 @@ +import anymatch = require('anymatch'); + +const matchers = [ + 'path/to/file.js', + 'path/anyjs/**/*.js', + /foo\.js$/, + (str: string) => str.indexOf('bar') !== -1 && str.length > 10 +]; + +// $ExpectType boolean +anymatch(matchers, 'path/to/file.js'); +// $ExpectType boolean +anymatch(matchers, 'path/to/file.js', false); +// $ExpectType boolean +anymatch(matchers, 'path/to/file.js', false, 1); +// $ExpectType boolean +anymatch(matchers, 'path/to/file.js', false, 1, 2); + +// $ExpectType number +anymatch(matchers, 'foo.js', true); +// $ExpectType number +anymatch(matchers, 'path/anyjs/foo.js', true, 2); +// $ExpectType number +anymatch(matchers, 'path/anyjs/foo.js', true, 2, 3); + +const matcher = anymatch(matchers); +// $ExpectType boolean +matcher('path/to/file.js'); +// $ExpectType boolean +matcher('path/to/file.js', false); +// $ExpectType boolean +matcher('path/to/file.js', false, 1); +// $ExpectType boolean +matcher('path/to/file.js', false, 1, 2); +// $ExpectType number +matcher('path/anyjs/baz.js', true); +// $ExpectType number +matcher('path/anyjs/baz.js', true, 2); +// $ExpectType number +matcher('path/anyjs/baz.js', true, 2, 3); + +// tslint:disable-next-line no-unnecessary-callback-wrapper +['foo.js', 'bar.js'].filter(str => matcher(str)); diff --git a/types/anymatch/index.d.ts b/types/anymatch/index.d.ts new file mode 100644 index 0000000000..4eb90734a4 --- /dev/null +++ b/types/anymatch/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for anymatch 1.3 +// Project: https://github.com/es128/anymatch +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = anymatch; + +declare function anymatch(matcher: anymatch.Matcher): CurrriedMatcher; +declare function anymatch(matcher: anymatch.Matcher, testString: string | string[], returnIndex: true, startIndex?: number, endIndex?: number): number; +declare function anymatch(matcher: anymatch.Matcher, testString: string | string[], returnIndex?: boolean, startIndex?: number, endIndex?: number): boolean; + +declare namespace anymatch { + type Matcher = MatcherType | MatcherType[]; + type MatcherType = string | RegExp | ((...testStrings: string[]) => boolean); +} + +interface CurrriedMatcher { + (testString: string | string[], returnIndex: true, startIndex?: number, endIndex?: number): number; + (testString: string | string[], returnIndex?: boolean, startIndex?: number, endIndex?: number): boolean; +} diff --git a/types/anymatch/tsconfig.json b/types/anymatch/tsconfig.json new file mode 100644 index 0000000000..e4fad1c219 --- /dev/null +++ b/types/anymatch/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "anymatch-tests.ts" + ] +} diff --git a/types/anymatch/tslint.json b/types/anymatch/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/anymatch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }