.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / fast-glob / out / providers / filters / entry.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 EntryFilter = /** @class */ (function () {\r
6     function EntryFilter(options, micromatchOptions) {\r
7         this.options = options;\r
8         this.micromatchOptions = micromatchOptions;\r
9         this.index = new Map();\r
10     }\r
11     /**\r
12      * Returns filter for directories.\r
13      */\r
14     EntryFilter.prototype.getFilter = function (positive, negative) {\r
15         var _this = this;\r
16         var positiveRe = patternUtils.convertPatternsToRe(positive, this.micromatchOptions);\r
17         var negativeRe = patternUtils.convertPatternsToRe(negative, this.micromatchOptions);\r
18         return function (entry) { return _this.filter(entry, positiveRe, negativeRe); };\r
19     };\r
20     /**\r
21      * Returns true if entry must be added to result.\r
22      */\r
23     EntryFilter.prototype.filter = function (entry, positiveRe, negativeRe) {\r
24         // Exclude duplicate results\r
25         if (this.options.unique) {\r
26             if (this.isDuplicateEntry(entry)) {\r
27                 return false;\r
28             }\r
29             this.createIndexRecord(entry);\r
30         }\r
31         // Filter files and directories by options\r
32         if (this.onlyFileFilter(entry) || this.onlyDirectoryFilter(entry)) {\r
33             return false;\r
34         }\r
35         if (this.isSkippedByAbsoluteNegativePatterns(entry, negativeRe)) {\r
36             return false;\r
37         }\r
38         return this.isMatchToPatterns(entry.path, positiveRe) && !this.isMatchToPatterns(entry.path, negativeRe);\r
39     };\r
40     /**\r
41      * Return true if the entry already has in the cross reader index.\r
42      */\r
43     EntryFilter.prototype.isDuplicateEntry = function (entry) {\r
44         return this.index.has(entry.path);\r
45     };\r
46     /**\r
47      * Create record in the cross reader index.\r
48      */\r
49     EntryFilter.prototype.createIndexRecord = function (entry) {\r
50         this.index.set(entry.path, undefined);\r
51     };\r
52     /**\r
53      * Returns true for non-files if the «onlyFiles» option is enabled.\r
54      */\r
55     EntryFilter.prototype.onlyFileFilter = function (entry) {\r
56         return this.options.onlyFiles && !entry.isFile();\r
57     };\r
58     /**\r
59      * Returns true for non-directories if the «onlyDirectories» option is enabled.\r
60      */\r
61     EntryFilter.prototype.onlyDirectoryFilter = function (entry) {\r
62         return this.options.onlyDirectories && !entry.isDirectory();\r
63     };\r
64     /**\r
65      * Return true when `absolute` option is enabled and matched to the negative patterns.\r
66      */\r
67     EntryFilter.prototype.isSkippedByAbsoluteNegativePatterns = function (entry, negativeRe) {\r
68         if (!this.options.absolute) {\r
69             return false;\r
70         }\r
71         var fullpath = pathUtils.makeAbsolute(this.options.cwd, entry.path);\r
72         return this.isMatchToPatterns(fullpath, negativeRe);\r
73     };\r
74     /**\r
75      * Return true when entry match to provided patterns.\r
76      *\r
77      * First, just trying to apply patterns to the path.\r
78      * Second, trying to apply patterns to the path with final slash (need to micromatch to support «directory/**» patterns).\r
79      */\r
80     EntryFilter.prototype.isMatchToPatterns = function (filepath, patternsRe) {\r
81         return patternUtils.matchAny(filepath, patternsRe) || patternUtils.matchAny(filepath + '/', patternsRe);\r
82     };\r
83     return EntryFilter;\r
84 }());\r
85 exports.default = EntryFilter;\r