source: trip-planner-front/node_modules/fast-glob/out/providers/filters/deep.js

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

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const utils = require("../../utils");
4const partial_1 = require("../matchers/partial");
5class DeepFilter {
6 constructor(_settings, _micromatchOptions) {
7 this._settings = _settings;
8 this._micromatchOptions = _micromatchOptions;
9 }
10 getFilter(basePath, positive, negative) {
11 const matcher = this._getMatcher(positive);
12 const negativeRe = this._getNegativePatternsRe(negative);
13 return (entry) => this._filter(basePath, entry, matcher, negativeRe);
14 }
15 _getMatcher(patterns) {
16 return new partial_1.default(patterns, this._settings, this._micromatchOptions);
17 }
18 _getNegativePatternsRe(patterns) {
19 const affectDepthOfReadingPatterns = patterns.filter(utils.pattern.isAffectDepthOfReadingPattern);
20 return utils.pattern.convertPatternsToRe(affectDepthOfReadingPatterns, this._micromatchOptions);
21 }
22 _filter(basePath, entry, matcher, negativeRe) {
23 if (this._isSkippedByDeep(basePath, entry.path)) {
24 return false;
25 }
26 if (this._isSkippedSymbolicLink(entry)) {
27 return false;
28 }
29 const filepath = utils.path.removeLeadingDotSegment(entry.path);
30 if (this._isSkippedByPositivePatterns(filepath, matcher)) {
31 return false;
32 }
33 return this._isSkippedByNegativePatterns(filepath, negativeRe);
34 }
35 _isSkippedByDeep(basePath, entryPath) {
36 /**
37 * Avoid unnecessary depth calculations when it doesn't matter.
38 */
39 if (this._settings.deep === Infinity) {
40 return false;
41 }
42 return this._getEntryLevel(basePath, entryPath) >= this._settings.deep;
43 }
44 _getEntryLevel(basePath, entryPath) {
45 const entryPathDepth = entryPath.split('/').length;
46 if (basePath === '') {
47 return entryPathDepth;
48 }
49 const basePathDepth = basePath.split('/').length;
50 return entryPathDepth - basePathDepth;
51 }
52 _isSkippedSymbolicLink(entry) {
53 return !this._settings.followSymbolicLinks && entry.dirent.isSymbolicLink();
54 }
55 _isSkippedByPositivePatterns(entryPath, matcher) {
56 return !this._settings.baseNameMatch && !matcher.match(entryPath);
57 }
58 _isSkippedByNegativePatterns(entryPath, patternsRe) {
59 return !utils.pattern.matchAny(entryPath, patternsRe);
60 }
61}
62exports.default = DeepFilter;
Note: See TracBrowser for help on using the repository browser.