UNPKG

vitepress-jsdoc

Version:

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

44 lines 1.7 kB
import path from 'node:path'; import mm from '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} */ export 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 (mm.every(path.join(srcPath.replace(baseSrc, ''), entry.name), [ ...this.include, ...this.exclude.map((ex) => '!' + ex), ]) || entry.isDirectory()); } } //# sourceMappingURL=pattern-filter.js.map