.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / glob-parent / index.js
1 'use strict';
2
3 var isGlob = require('is-glob');
4 var pathPosixDirname = require('path').posix.dirname;
5 var isWin32 = require('os').platform() === 'win32';
6
7 var slash = '/';
8 var backslash = /\\/g;
9 var enclosure = /[\{\[].*[\}\]]$/;
10 var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
11 var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
12
13 /**
14  * @param {string} str
15  * @param {Object} opts
16  * @param {boolean} [opts.flipBackslashes=true]
17  * @returns {string}
18  */
19 module.exports = function globParent(str, opts) {
20   var options = Object.assign({ flipBackslashes: true }, opts);
21
22   // flip windows path separators
23   if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
24     str = str.replace(backslash, slash);
25   }
26
27   // special case for strings ending in enclosure containing path separator
28   if (enclosure.test(str)) {
29     str += slash;
30   }
31
32   // preserves full path in case of trailing path separator
33   str += 'a';
34
35   // remove path parts that are globby
36   do {
37     str = pathPosixDirname(str);
38   } while (isGlob(str) || globby.test(str));
39
40   // remove escape chars and return result
41   return str.replace(escaped, '$1');
42 };