Files
Tim van der Lippe eab929dec5 Run "npm audit fix"
Some packages have vulnerabilities, which can be fixed with
"npm audit fix". Unfortunately not all packages can be fixed,
as they are transitive dependencies that require major breaking
change updates from other packages. Luckily we are not affected
by these vulnerabilities in our frontend code.

R=aerotwist@chromium.org

Bug: none
Change-Id: I728411390ebbcb5240045aae5b67b4d8cfc540fb
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2949048
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2021-06-09 14:00:54 +00:00

43 lines
1.1 KiB
JavaScript

'use strict';
var isGlob = require('is-glob');
var pathPosixDirname = require('path').posix.dirname;
var isWin32 = require('os').platform() === 'win32';
var slash = '/';
var backslash = /\\/g;
var enclosure = /[\{\[].*[\}\]]$/;
var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
/**
* @param {string} str
* @param {Object} opts
* @param {boolean} [opts.flipBackslashes=true]
* @returns {string}
*/
module.exports = function globParent(str, opts) {
var options = Object.assign({ flipBackslashes: true }, opts);
// flip windows path separators
if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
str = str.replace(backslash, slash);
}
// special case for strings ending in enclosure containing path separator
if (enclosure.test(str)) {
str += slash;
}
// preserves full path in case of trailing path separator
str += 'a';
// remove path parts that are globby
do {
str = pathPosixDirname(str);
} while (isGlob(str) || globby.test(str));
// remove escape chars and return result
return str.replace(escaped, '$1');
};