Skip to content

Commit

Permalink
feat: new approach to braces/brackets handling
Browse files Browse the repository at this point in the history
  • Loading branch information
es128 authored and phated committed Jan 27, 2021
1 parent fadb8f5 commit 8269bd8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ var isglob = require('is-glob');
var pathDirname = require('path-dirname');

module.exports = function globParent(str) {
// replace braces/brackets sections with *
str = str.replace(/(^|[^\\])(\{([^{}]*?)}|\[([^\[\]]*?)\])/g, '$1*');
if (/[\}\]]$/.test(str)) str += '/';
// special case for strings ending in enclosure containing path separator
if (/[\{\[].*[\/]*.*[\}\]]$/.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));
do {str = pathDirname.posix(str)}
while (isglob(str) || /(^|[^\\])[\{\[]/.test(str));

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

0 comments on commit 8269bd8

Please sign in to comment.