-
-
Notifications
You must be signed in to change notification settings - Fork 482
/
has-magic.ts
26 lines (25 loc) · 933 Bytes
/
has-magic.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
import { Minimatch } from 'minimatch'
import { GlobOptions } from './glob.js'
/**
* Return true if the patterns provided contain any magic glob characters,
* given the options provided.
*
* Brace expansion is not considered "magic" unless the `magicalBraces` option
* is set, as brace expansion just turns one string into an array of strings.
* So a pattern like `'x{a,b}y'` would return `false`, because `'xay'` and
* `'xby'` both do not contain any magic glob characters, and it's treated the
* same as if you had called it on `['xay', 'xby']`. When `magicalBraces:true`
* is in the options, brace expansion _is_ treated as a pattern having magic.
*/
export const hasMagic = (
pattern: string | string[],
options: GlobOptions = {}
): boolean => {
if (!Array.isArray(pattern)) {
pattern = [pattern]
}
for (const p of pattern) {
if (new Minimatch(p, options).hasMagic()) return true
}
return false
}