Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

entry.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const utils = require("../../utils");
  4. class EntryFilter {
  5. constructor(_settings, _micromatchOptions) {
  6. this._settings = _settings;
  7. this._micromatchOptions = _micromatchOptions;
  8. this.index = new Map();
  9. }
  10. getFilter(positive, negative) {
  11. const positiveRe = utils.pattern.convertPatternsToRe(positive, this._micromatchOptions);
  12. const negativeRe = utils.pattern.convertPatternsToRe(negative, this._micromatchOptions);
  13. return (entry) => this._filter(entry, positiveRe, negativeRe);
  14. }
  15. _filter(entry, positiveRe, negativeRe) {
  16. if (this._settings.unique && this._isDuplicateEntry(entry)) {
  17. return false;
  18. }
  19. if (this._onlyFileFilter(entry) || this._onlyDirectoryFilter(entry)) {
  20. return false;
  21. }
  22. if (this._isSkippedByAbsoluteNegativePatterns(entry.path, negativeRe)) {
  23. return false;
  24. }
  25. const filepath = this._settings.baseNameMatch ? entry.name : entry.path;
  26. const isMatched = this._isMatchToPatterns(filepath, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
  27. if (this._settings.unique && isMatched) {
  28. this._createIndexRecord(entry);
  29. }
  30. return isMatched;
  31. }
  32. _isDuplicateEntry(entry) {
  33. return this.index.has(entry.path);
  34. }
  35. _createIndexRecord(entry) {
  36. this.index.set(entry.path, undefined);
  37. }
  38. _onlyFileFilter(entry) {
  39. return this._settings.onlyFiles && !entry.dirent.isFile();
  40. }
  41. _onlyDirectoryFilter(entry) {
  42. return this._settings.onlyDirectories && !entry.dirent.isDirectory();
  43. }
  44. _isSkippedByAbsoluteNegativePatterns(entryPath, patternsRe) {
  45. if (!this._settings.absolute) {
  46. return false;
  47. }
  48. const fullpath = utils.path.makeAbsolute(this._settings.cwd, entryPath);
  49. return utils.pattern.matchAny(fullpath, patternsRe);
  50. }
  51. _isMatchToPatterns(entryPath, patternsRe) {
  52. const filepath = utils.path.removeLeadingDotSegment(entryPath);
  53. return utils.pattern.matchAny(filepath, patternsRe);
  54. }
  55. }
  56. exports.default = EntryFilter;