Skip to content

Commit

Permalink
Merge c731dda into 6765192
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Sep 6, 2018
2 parents 6765192 + c731dda commit 7fb414f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.js
Expand Up @@ -5,20 +5,25 @@ var isglob = require('is-glob');
var pathDirname = require('path-dirname');
var isWin32 = require('os').platform() === 'win32';

// Reg exps out of fn to save mem.
var encRe = /[\{\[].*[\/]*.*[\}\]]$/;
var globRe = /(^|[^\\])([\{\[]|\([^\)]+$)/;
var escRe = /\\([\*\?\|\[\]\(\)\{\}])/g;

module.exports = function globParent(str) {
// flip windows path separators
if (isWin32 && str.indexOf('/') < 0) str = str.split('\\').join('/');

// special case for strings ending in enclosure containing path separator
if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/';
if (encRe.test(str)) str += '/';

// preserves full path in case of trailing path separator
str += 'a';

// remove path parts that are globby
do {str = pathDirname.posix(str)}
while (isglob(str) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(str));
while (isglob(str) || globRe.test(str));

// remove escape chars and return result
return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1');
return str.replace(escRe, '$1');
};

0 comments on commit 7fb414f

Please sign in to comment.