diff --git a/index.js b/index.js index b3a9fc6..4b8a4c4 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,9 @@ const isWindows = os.platform() === 'win32'; function picomatch(glob, options, returnState = false) { // default to os.platform() - if (options.windows === null || options.windows === undefined) { - options.windows = isWindows; + if (options && (options.windows === null || options.windows === undefined)) { + // don't mutate the original options object + options = { ...options, windows: isWindows }; } return pico(glob, options, returnState); } diff --git a/lib/utils.js b/lib/utils.js index c3ce77e..035cfe3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -20,9 +20,11 @@ exports.removeBackslashes = str => { }; exports.supportsLookbehinds = () => { - const segs = process.version.slice(1).split('.').map(Number); - if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) { - return true; + if (typeof process !== 'undefined') { + const segs = process.version.slice(1).split('.').map(Number); + if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) { + return true; + } } return false; }; @@ -55,9 +57,12 @@ exports.wrapOutput = (input, state = {}, options = {}) => { }; exports.basename = (path, { windows } = {}) => { - if (windows) { - return path.replace(/[\\/]$/, '').replace(/.*[\\/]/, ''); - } else { - return path.replace(/\/$/, '').replace(/.*\//, ''); + const segs = path.split(windows ? /[\\/]/ : '/'); + const last = segs[segs.length - 1]; + + if (last === '') { + return segs[segs.length - 2]; } + + return last; }; diff --git a/package.json b/package.json index 94df1ea..f398b47 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "picomatch", "description": "Blazing fast and accurate glob matcher written in JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.", - "version": "2.3.1", + "version": "3.0.0", "homepage": "https://github.com/micromatch/picomatch", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "funding": "https://github.com/sponsors/jonschlinkert", diff --git a/test/dotfiles.js b/test/dotfiles.js index e72e0f6..f90abb8 100644 --- a/test/dotfiles.js +++ b/test/dotfiles.js @@ -224,7 +224,7 @@ describe('dotfiles', () => { assert(isMatch('abc/../abc', '*/../*')); }); - it('should not match double dots when not defined in pattern', async() => { + it('should not match double dots when not defined in pattern', async () => { assert(!isMatch('../abc', '**/*')); assert(!isMatch('../abc', '**/**/**')); assert(!isMatch('../abc', '**/**/abc')); @@ -291,7 +291,7 @@ describe('dotfiles', () => { assert(!isMatch('abc/abc/..', 'abc/*/**/*', { strictSlashes: true })); }); - it('should not match single exclusive dots when not defined in pattern', async() => { + it('should not match single exclusive dots when not defined in pattern', async () => { assert(!isMatch('.', '**')); assert(!isMatch('abc/./abc', '**')); assert(!isMatch('abc/abc/.', '**')); diff --git a/test/special-characters.js b/test/special-characters.js index f9c4054..c6958a5 100644 --- a/test/special-characters.js +++ b/test/special-characters.js @@ -226,7 +226,7 @@ describe('special characters', () => { assert(isMatch('foo(bar)baz', 'foo*baz')); }); - it('should match literal parens with brackets', async() => { + it('should match literal parens with brackets', async () => { assert(isMatch('foo(bar)baz', 'foo[bar()]+baz')); });