.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / fast-glob / package / out / providers / filters / deep.js
1 "use strict";\r
2 Object.defineProperty(exports, "__esModule", { value: true });\r
3 var pathUtils = require("../../utils/path");\r
4 var patternUtils = require("../../utils/pattern");\r
5 var DeepFilter = /** @class */ (function () {\r
6     function DeepFilter(options, micromatchOptions) {\r
7         this.options = options;\r
8         this.micromatchOptions = micromatchOptions;\r
9     }\r
10     /**\r
11      * Returns filter for directories.\r
12      */\r
13     DeepFilter.prototype.getFilter = function (positive, negative) {\r
14         var _this = this;\r
15         var maxPatternDepth = this.getMaxPatternDepth(positive);\r
16         var negativeRe = this.getNegativePatternsRe(negative);\r
17         return function (entry) { return _this.filter(entry, negativeRe, maxPatternDepth); };\r
18     };\r
19     /**\r
20      * Returns max depth of the provided patterns.\r
21      */\r
22     DeepFilter.prototype.getMaxPatternDepth = function (patterns) {\r
23         var globstar = patterns.some(patternUtils.hasGlobStar);\r
24         return globstar ? Infinity : patternUtils.getMaxNaivePatternsDepth(patterns);\r
25     };\r
26     /**\r
27      * Returns RegExp's for patterns that can affect the depth of reading.\r
28      */\r
29     DeepFilter.prototype.getNegativePatternsRe = function (patterns) {\r
30         var affectDepthOfReadingPatterns = patterns.filter(patternUtils.isAffectDepthOfReadingPattern);\r
31         return patternUtils.convertPatternsToRe(affectDepthOfReadingPatterns, this.micromatchOptions);\r
32     };\r
33     /**\r
34      * Returns «true» for directory that should be read.\r
35      */\r
36     DeepFilter.prototype.filter = function (entry, negativeRe, maxPatternDepth) {\r
37         if (this.isSkippedByDeepOption(entry.depth)) {\r
38             return false;\r
39         }\r
40         if (this.isSkippedByMaxPatternDepth(entry.depth, maxPatternDepth)) {\r
41             return false;\r
42         }\r
43         if (this.isSkippedSymlinkedDirectory(entry)) {\r
44             return false;\r
45         }\r
46         if (this.isSkippedDotDirectory(entry)) {\r
47             return false;\r
48         }\r
49         return this.isSkippedByNegativePatterns(entry, negativeRe);\r
50     };\r
51     /**\r
52      * Returns «true» when the «deep» option is disabled or number and depth of the entry is greater that the option value.\r
53      */\r
54     DeepFilter.prototype.isSkippedByDeepOption = function (entryDepth) {\r
55         return !this.options.deep || (typeof this.options.deep === 'number' && entryDepth >= this.options.deep);\r
56     };\r
57     /**\r
58      * Returns «true» when depth parameter is not an Infinity and entry depth greater that the parameter value.\r
59      */\r
60     DeepFilter.prototype.isSkippedByMaxPatternDepth = function (entryDepth, maxPatternDepth) {\r
61         return maxPatternDepth !== Infinity && entryDepth >= maxPatternDepth;\r
62     };\r
63     /**\r
64      * Returns «true» for symlinked directory if the «followSymlinkedDirectories» option is disabled.\r
65      */\r
66     DeepFilter.prototype.isSkippedSymlinkedDirectory = function (entry) {\r
67         return !this.options.followSymlinkedDirectories && entry.isSymbolicLink();\r
68     };\r
69     /**\r
70      * Returns «true» for a directory whose name starts with a period if «dot» option is disabled.\r
71      */\r
72     DeepFilter.prototype.isSkippedDotDirectory = function (entry) {\r
73         return !this.options.dot && pathUtils.isDotDirectory(entry.path);\r
74     };\r
75     /**\r
76      * Returns «true» for a directory whose path math to any negative pattern.\r
77      */\r
78     DeepFilter.prototype.isSkippedByNegativePatterns = function (entry, negativeRe) {\r
79         return !patternUtils.matchAny(entry.path, negativeRe);\r
80     };\r
81     return DeepFilter;\r
82 }());\r
83 exports.default = DeepFilter;\r