mirror of
https://github.com/al0cam/AutoMover.git
synced 2026-07-22 12:10:26 +00:00
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
import type { ExclusionRule } from "Models/ExclusionRule";
|
|
import type { TFile } from "obsidian";
|
|
|
|
class ExclusionMatcherUtil {
|
|
private static instance: ExclusionMatcherUtil;
|
|
|
|
private constructor() {}
|
|
|
|
public static getInstance(): ExclusionMatcherUtil {
|
|
if (!ExclusionMatcherUtil.instance) {
|
|
ExclusionMatcherUtil.instance = new ExclusionMatcherUtil();
|
|
}
|
|
return ExclusionMatcherUtil.instance;
|
|
}
|
|
|
|
/**
|
|
* This method is used to check if the file is excluded by the exclusion rule
|
|
* @param file - The file to be checked
|
|
* @param exclusionRules - The exclusion rule to be used
|
|
* @returns true if the file path is excluded, false otherwise
|
|
*/
|
|
isFilePathExcluded(file: TFile, exclusionRules: ExclusionRule[]): boolean {
|
|
for (const rule of exclusionRules) {
|
|
const regex = new RegExp(rule.regex);
|
|
if (regex.test(file.path)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
const exclusionMatcherUtil = ExclusionMatcherUtil.getInstance();
|
|
export default exclusionMatcherUtil;
|