createMatcher
Turns user-supplied filters (a setting, a CLI flag, a list of rules) into one predicate.
- A string is a glob, or a regular expression — see MatcherOptions.syntax. A
re:orglob:prefix ('re:^v\\d+$','glob:*.ts') fixes the reading of that one pattern when the syntax is'auto'(the default); with an explicit'glob'or'regex'syntax the prefixes are plain text, so createGlobMatcher never reads a regular expression. To match a string that really starts with one of them under'auto', spell it'glob:re:…'. - A
RegExpis used as is, except that itsgandyflags are dropped: they maketest()depend on the previous call. - A function is called as is.
- An array matches when one of its patterns matches and none of its exclusions does. An
exclusion is a string starting with
!('!draft-*'); write'\\!'for a pattern that really starts with!. The order does not matter. An array with only exclusions matches everything else, and an empty array matches everything (no filter).
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
pattern | MatcherPattern | readonly MatcherPattern[] | A pattern, or an array of patterns and exclusions |
options | MatcherOptions | Syntax of string patterns and case sensitivity — see MatcherOptions |
Returns
Section titled “Returns”function — A function telling whether a string matches
Examples
Section titled “Examples”Filter names with globs, regular expressions and exclusions
Section titled “Filter names with globs, regular expressions and exclusions”An array matches when one pattern matches and no ! exclusion does.
Paths only
Section titled “Paths only”With syntax ‘glob’, a pattern like /usr/lib/img is never read as a regular expression.
Fix the reading of one pattern with re: or glob:
Section titled “Fix the reading of one pattern with re: or glob:”A prefix overrides the syntax option for that pattern only, so globs and regular expressions mix freely.
Related Types
Section titled “Related Types”MatcherOptions
Section titled “MatcherOptions”Options for createMatcher and createSafeMatcher.
MatcherPattern
Section titled “MatcherPattern”One pattern accepted by createMatcher: a string (read according to
MatcherOptions.syntax), a RegExp, or a predicate of your own.
