forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
micromatch.d.ts
174 lines (150 loc) · 5.67 KB
/
micromatch.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Type definitions for micromatch 2.3.7
// Project: https://github.com/jonschlinkert/micromatch
// Definitions by: glen-84 <https://github.com/glen-84>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../parse-glob/parse-glob.d.ts" />
declare module 'micromatch' {
import parseGlob = require('parse-glob');
namespace micromatch {
type MatchFunction<T> = ((value: T) => boolean);
type Pattern = (string | RegExp | MatchFunction<string>);
interface Options {
/**
* Normalize slashes in file paths and glob patterns to forward slashes.
*/
unixify?: boolean;
/**
* Match dotfiles. Same behavior as minimatch.
*/
dot?: boolean;
/**
* Unescape slashes in glob patterns. Use cautiously, especially on windows.
*/
unescape?: boolean;
/**
* Remove duplicate elements from the result array.
*/
nodupes?: boolean;
/**
* Allow glob patterns without slashes to match a file path based on its basename. Same behavior as
* minimatch.
*/
matchBase?: boolean;
/**
* Don't expand braces in glob patterns. Same behavior as minimatch nobrace.
*/
nobraces?: boolean;
/**
* Don't expand POSIX bracket expressions.
*/
nobrackets?: boolean;
/**
* Don't expand extended globs.
*/
noextglob?: boolean;
/**
* Use a case-insensitive regex for matching files. Same behavior as minimatch.
*/
nocase?: boolean;
/**
* If true, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty
* array. Same behavior as minimatch.
*/
nonull?: boolean;
/**
* Cache the platform (e.g. win32) to prevent this from being looked up for every file path.
*/
cache?: boolean;
}
interface Glob {
options: micromatch.Options;
pattern: string;
history: {msg: any, pattern: string}[];
tokens: parseGlob.Result;
orig: string;
negated: boolean;
/**
* Initialize defaults.
*/
init(pattern: string): void;
/**
* Push a change into `glob.history`. Useful for debugging.
*/
track(msg: any): void;
/**
* Return true if `glob.pattern` was negated with `!`, also remove the `!` from the pattern.
*/
isNegated(): boolean;
/**
* Expand braces in the given glob pattern.
*/
braces(): void;
/**
* Expand bracket expressions in `glob.pattern`.
*/
brackets(): void;
/**
* Expand extended globs in `glob.pattern`.
*/
extglob(): void;
/**
* Parse the given pattern.
*/
parse(pattern: string): parseGlob.Result;
/**
* Escape special characters in the given string.
*/
escape(pattern: string): string;
/**
* Unescape special characters in the given string.
*/
unescape(pattern: string): string;
}
interface GlobData {
pattern: string;
tokens: parseGlob.Result;
options: micromatch.Options;
}
}
interface Micromatch {
(files: string | string[], patterns: micromatch.Pattern | micromatch.Pattern[]): string[];
isMatch: {
/**
* Returns true if a file path matches the given pattern.
*/
(filePath: string, pattern: micromatch.Pattern, opts?: micromatch.Options): boolean;
/**
* Returns a function for matching.
*/
(filePath: string, opts?: micromatch.Options): micromatch.MatchFunction<string>;
};
/**
* Returns true if any part of a file path matches the given pattern. Think of this as "has path" versus
* "is path".
*/
contains(filePath: string, pattern: micromatch.Pattern, opts?: micromatch.Options): boolean;
/**
* Returns a function for matching using the supplied pattern. e.g. create your own "matcher". The advantage of
* this method is that the pattern can be compiled outside of a loop.
*/
matcher(pattern: micromatch.Pattern): micromatch.MatchFunction<string>;
/**
* Returns a function that can be passed to Array#filter().
*/
filter(patterns: micromatch.Pattern | micromatch.Pattern[], opts?: micromatch.Options): micromatch.MatchFunction<any>;
/**
* Returns true if a file path matches any of the given patterns.
*/
any(filePath: string, patterns: micromatch.Pattern | micromatch.Pattern[], opts?: micromatch.Options): boolean;
/**
* Returns an object with a regex-compatible string and tokens.
*/
expand(pattern: string, opts?: micromatch.Options): micromatch.Glob | micromatch.GlobData;
/**
* Create a regular expression for matching file paths based on the given pattern.
*/
makeRe(pattern: string, opts?: micromatch.Options): RegExp;
}
const micromatch: Micromatch;
export = micromatch;
}