| 1 | "use strict";
|
|---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
|---|
| 3 | exports.escape = void 0;
|
|---|
| 4 | /**
|
|---|
| 5 | * Escape all magic characters in a glob pattern.
|
|---|
| 6 | *
|
|---|
| 7 | * If the {@link MinimatchOptions.windowsPathsNoEscape}
|
|---|
| 8 | * option is used, then characters are escaped by wrapping in `[]`, because
|
|---|
| 9 | * a magic character wrapped in a character class can only be satisfied by
|
|---|
| 10 | * that exact character. In this mode, `\` is _not_ escaped, because it is
|
|---|
| 11 | * not interpreted as a magic character, but instead as a path separator.
|
|---|
| 12 | *
|
|---|
| 13 | * If the {@link MinimatchOptions.magicalBraces} option is used,
|
|---|
| 14 | * then braces (`{` and `}`) will be escaped.
|
|---|
| 15 | */
|
|---|
| 16 | const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false, } = {}) => {
|
|---|
| 17 | // don't need to escape +@! because we escape the parens
|
|---|
| 18 | // that make those magic, and escaping ! as [!] isn't valid,
|
|---|
| 19 | // because [!]] is a valid glob class meaning not ']'.
|
|---|
| 20 | if (magicalBraces) {
|
|---|
| 21 | return windowsPathsNoEscape ?
|
|---|
| 22 | s.replace(/[?*()[\]{}]/g, '[$&]')
|
|---|
| 23 | : s.replace(/[?*()[\]\\{}]/g, '\\$&');
|
|---|
| 24 | }
|
|---|
| 25 | return windowsPathsNoEscape ?
|
|---|
| 26 | s.replace(/[?*()[\]]/g, '[$&]')
|
|---|
| 27 | : s.replace(/[?*()[\]\\]/g, '\\$&');
|
|---|
| 28 | };
|
|---|
| 29 | exports.escape = escape;
|
|---|
| 30 | //# sourceMappingURL=escape.js.map |
|---|