codekingpro/portable-devtools
114k
1/**
2 * Un-escape a string that has been escaped with {@link escape}.
3 *
4 * If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
5 * square-bracket escapes are removed, but not backslash escapes.
6 *
7 * For example, it will turn the string `'[*]'` into `*`, but it will not
8 * turn `'\\*'` into `'*'`, because `\` is a path separator in
9 * `windowsPathsNoEscape` mode.
10 *
11 * When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
12 * backslash escapes are removed.
13 *
14 * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
15 * or unescaped.
16 *
17 * When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
18 * unescaped.
19 */
20export const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true, } = {}) => {
21 if (magicalBraces) {
22 return windowsPathsNoEscape ?
23 s.replace(/\[([^\/\\])\]/g, '$1')
24 : s
25 .replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2')
26 .replace(/\\([^\/])/g, '$1');
27 }
28 return windowsPathsNoEscape ?
29 s.replace(/\[([^\/\\{}])\]/g, '$1')
30 : s
31 .replace(/((?!\\).|^)\[([^\/\\{}])\]/g, '$1$2')
32 .replace(/\\([^\/{}])/g, '$1');
33};
34//# sourceMappingURL=unescape.js.map