UNPKG

vitepress-jsdoc

Version:

A bridge between Vitepress and JSDoc-style commented codebases for hassle-free documentation.

51 lines 2.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PatternFilter = void 0; const node_path_1 = __importDefault(require("node:path")); const micromatch_1 = __importDefault(require("micromatch")); /** * Represents a filter strategy that determines the inclusion of directory entries * based on specified include and exclude patterns. This class leverages the `micromatch` * library to perform pattern matching. * * @implements {FilterStrategy} */ class PatternFilter { include; exclude; /** * Initializes a new instance of the PatternFilter class. * * @param {string[]} include - Patterns that specify which entries to include. * @param {string[]} exclude - Patterns that specify which entries to exclude. */ constructor(include, exclude) { this.include = include; this.exclude = exclude; } /** * Determines whether a given directory entry should be included based on the * provided include and exclude patterns. * * @param {DirectoryEntity} entry - The directory entry to evaluate. * @param {string} srcPath - The source directory path. * @param {string} mainPath - The main directory path for relative path calculations. * @returns {boolean} Returns true if the entry matches the inclusion criteria, false otherwise. * * @example * const filter = new PatternFilter(['*.js'], ['test.js']); * const shouldInclude = filter.shouldInclude(entry, './src', './main'); */ shouldInclude(entry, srcPath, mainPath) { const baseSrc = mainPath || srcPath; return (micromatch_1.default.every(node_path_1.default.join(srcPath.replace(baseSrc, ''), entry.name), [ ...this.include, ...this.exclude.map((ex) => '!' + ex), ]) || entry.isDirectory()); } } exports.PatternFilter = PatternFilter; //# sourceMappingURL=pattern-filter.js.map