[anymatch] add typings (#18921)

This commit is contained in:
Dimitri Benin
2017-08-14 10:07:11 -07:00
committed by Mohamed Hegazy
parent 67e320cf41
commit 2b91b27c3f
4 changed files with 86 additions and 0 deletions
+43
View File
@@ -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));
+20
View File
@@ -0,0 +1,20 @@
// Type definitions for anymatch 1.3
// Project: https://github.com/es128/anymatch
// Definitions by: BendingBender <https://github.com/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;
}
+22
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }