3 var path = require('path');
4 var isglob = require('is-glob');
5 var pathDirname = require('path-dirname');
6 var isWin32 = require('os').platform() === 'win32';
8 module.exports = function globParent(str) {
9 // flip windows path separators
10 if (isWin32 && str.indexOf('/') < 0) str = str.split('\\').join('/');
12 // special case for strings ending in enclosure containing path separator
13 if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/';
15 // preserves full path in case of trailing path separator
18 // remove path parts that are globby
19 do {str = pathDirname.posix(str)}
20 while (isglob(str) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(str));
22 // remove escape chars and return result
23 return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1');