source: trip-planner-front/node_modules/glob-parent/index.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1'use strict';
2
3var isGlob = require('is-glob');
4var pathPosixDirname = require('path').posix.dirname;
5var isWin32 = require('os').platform() === 'win32';
6
7var slash = '/';
8var backslash = /\\/g;
9var enclosure = /[\{\[].*[\}\]]$/;
10var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
11var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
12
13/**
14 * @param {string} str
15 * @param {Object} opts
16 * @param {boolean} [opts.flipBackslashes=true]
17 * @returns {string}
18 */
19module.exports = function globParent(str, opts) {
20 var options = Object.assign({ flipBackslashes: true }, opts);
21
22 // flip windows path separators
23 if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
24 str = str.replace(backslash, slash);
25 }
26
27 // special case for strings ending in enclosure containing path separator
28 if (enclosure.test(str)) {
29 str += slash;
30 }
31
32 // preserves full path in case of trailing path separator
33 str += 'a';
34
35 // remove path parts that are globby
36 do {
37 str = pathPosixDirname(str);
38 } while (isGlob(str) || globby.test(str));
39
40 // remove escape chars and return result
41 return str.replace(escaped, '$1');
42};
Note: See TracBrowser for help on using the repository browser.