Class: IgnoreProcessor

IgnoreProcessor(customIgnoreFiles, configPathopt)

A class that processes and manages ignore patterns from various ignore files (e.g., .gitignore, .npmignore). Handles loading and applying ignore patterns from standard ignore files, custom ignore files, and directory-specific ignore files.

Constructor

new IgnoreProcessor(customIgnoreFiles, configPathopt)

Constructs an IgnoreProcessor instance.

Parameters:
Name Type Attributes Default Description
customIgnoreFiles Array.<string>

Array of custom ignore file paths.

configPath string <optional>
null

Path to a custom configuration file containing default ignore patterns.

Properties:
Name Type Description
ig ignore

Instance of the ignore package for pattern matching

standardIgnoreFiles Array.<string>

List of standard ignore file names to look for

Source:
Example
const processor = new IgnoreProcessor(['/path/to/custom/ignore'], '/path/to/config.json');
if (processor.isIgnored('file/to/check.js')) {
  console.log('This file is ignored');
}

Methods

addPatterns(patterns)

Adds additional patterns to the ignore instance. Useful for dynamically adding patterns during traversal.

Parameters:
Name Type Description
patterns Array.<string>

Array of ignore patterns to add.

Source:

isIgnored(filePath) → {boolean}

Determines if a given file path should be ignored based on loaded patterns.

Parameters:
Name Type Description
filePath string

Relative file path to check.

Source:
Returns:
  • Returns true if the file is ignored; otherwise, false.
Type
boolean

loadCustomIgnoreFiles(customIgnoreFiles)

Loads and processes custom ignore files provided by the user.

Parameters:
Name Type Description
customIgnoreFiles Array.<string>

Array of custom ignore file paths.

Source:

loadDefaultPatterns(configPath)

Loads default ignore patterns from a JSON configuration file.

Parameters:
Name Type Default Description
configPath string | null null

Path to the JSON configuration file.

Source:

loadIgnorePatternsFromDirectory(dirPath) → {Array.<string>}

Loads and processes ignore patterns from a specific directory's ignore files. This method is used to handle ignore files in subdirectories during traversal.

Parameters:
Name Type Description
dirPath string

Absolute path of the directory to check for ignore files.

Source:
Returns:
  • Array of ignore patterns found in the directory.
Type
Array.<string>