source: node_modules/minimatch/dist/esm/escape.js

main
Last change on this file was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[81bc7da]1/**
2 * Escape all magic characters in a glob pattern.
3 *
4 * If the {@link MinimatchOptions.windowsPathsNoEscape}
5 * option is used, then characters are escaped by wrapping in `[]`, because
6 * a magic character wrapped in a character class can only be satisfied by
7 * that exact character. In this mode, `\` is _not_ escaped, because it is
8 * not interpreted as a magic character, but instead as a path separator.
9 *
10 * If the {@link MinimatchOptions.magicalBraces} option is used,
11 * then braces (`{` and `}`) will be escaped.
12 */
13export const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false, } = {}) => {
14 // don't need to escape +@! because we escape the parens
15 // that make those magic, and escaping ! as [!] isn't valid,
16 // because [!]] is a valid glob class meaning not ']'.
17 if (magicalBraces) {
18 return windowsPathsNoEscape ?
19 s.replace(/[?*()[\]{}]/g, '[$&]')
20 : s.replace(/[?*()[\]\\{}]/g, '\\$&');
21 }
22 return windowsPathsNoEscape ?
23 s.replace(/[?*()[\]]/g, '[$&]')
24 : s.replace(/[?*()[\]\\]/g, '\\$&');
25};
26//# sourceMappingURL=escape.js.map
Note: See TracBrowser for help on using the repository browser.