-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matches-glob.mts
63 lines (57 loc) · 1.52 KB
/
matches-glob.mts
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
/**
* @file matchesGlob
* @module pathe/lib/matchesGlob
*/
import process from '#internal/process'
import validateString from '#internal/validate-string'
import validateURLString from '#internal/validate-url-string'
import toPosix from '#lib/to-posix'
import micromatch from 'micromatch'
/**
* Check if `input` matches `pattern`.
*
* @see {@linkcode micromatch.Options}
* @see {@linkcode micromatch.isMatch}
*
* @category
* core
*
* @this {void}
*
* @param {URL | string} input
* The {@linkcode URL}, URL string, or path to glob-match against
* @param {string | string[]} pattern
* Glob patterns to use for matching
* @param {micromatch.Options | null | undefined} [options]
* Options for matching
* @return {boolean}
* `true` if `input` matches `pattern`, `false` otherwise
*/
function matchesGlob(
this: void,
input: URL | string,
pattern: string | string[],
options?: micromatch.Options | null | undefined
): boolean {
validateURLString(input, 'input')
if (Array.isArray<string>(pattern)) {
/**
* Current index in {@linkcode pattern}.
*
* @var {number} i
*/
let i: number = -1
while (++i < pattern.length) validateString(pattern[i], `pattern[${i}]`)
pattern = toPosix(pattern)
} else {
validateString(pattern, 'pattern')
pattern = toPosix(pattern)
}
return micromatch.isMatch(toPosix(String(input)), pattern, {
...options,
basename: options?.basename ?? true,
cwd: options?.cwd ?? process.cwd(),
windows: false
})
}
export default matchesGlob