export interface IRelativePattern { /** * A base file path to which this pattern will be matched against relatively. */ readonly base: string; /** * A file glob pattern like `*.{ts,js}` that will be matched on file paths * relative to the base path. * * Example: Given a base of `/home/work/folder` and a file path of `/home/work/folder/index.js`, * the file glob pattern will match on `index.js`. */ readonly pattern: string; } export interface IExpression { [pattern: string]: boolean | SiblingClause; } export declare function getEmptyExpression(): IExpression; interface SiblingClause { when: string; } export declare const GLOBSTAR = "**"; export declare const GLOB_SPLIT = "/"; export declare function splitGlobAware(pattern: string, splitChar: string): string[]; export type ParsedPattern = (path: string, basename?: string) => boolean; export type ParsedExpression = (path: string, basename?: string, hasSibling?: (name: string) => boolean | Promise) => string | null | Promise; export interface IGlobOptions { /** * Simplify patterns for use as exclusion filters during * tree traversal to skip entire subtrees. Cannot be used * outside of a tree traversal. */ trimForExclusions?: boolean; /** * Whether glob pattern matching should be case insensitive. */ ignoreCase?: boolean; } declare const FALSE: () => boolean; declare const NULL: () => string | null; /** * Check if a provided parsed pattern or expression * is empty - hence it won't ever match anything. * * See {@link FALSE} and {@link NULL}. */ export declare function isEmptyPattern(pattern: ParsedPattern | ParsedExpression): pattern is (typeof FALSE | typeof NULL); /** * Simplified glob matching. Supports a subset of glob patterns: * * `*` to match zero or more characters in a path segment * * `?` to match on one character in a path segment * * `**` to match any number of path segments, including none * * `{}` to group conditions (e.g. *.{ts,js} matches all TypeScript and JavaScript files) * * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …) * * `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`) */ export declare function match(pattern: string | IRelativePattern, path: string, options?: IGlobOptions): boolean; export declare function match(expression: IExpression, path: string, options?: IGlobOptions): boolean; /** * Simplified glob matching. Supports a subset of glob patterns: * * `*` to match zero or more characters in a path segment * * `?` to match on one character in a path segment * * `**` to match any number of path segments, including none * * `{}` to group conditions (e.g. *.{ts,js} matches all TypeScript and JavaScript files) * * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …) * * `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`) */ export declare function parse(pattern: string | IRelativePattern, options?: IGlobOptions): ParsedPattern; export declare function parse(expression: IExpression, options?: IGlobOptions): ParsedExpression; export declare function parse(arg1: string | IExpression | IRelativePattern, options?: IGlobOptions): ParsedPattern | ParsedExpression; /** * Regular expression source that matches the keys of exclude exceptions, for use in JSON schemas. */ export declare const EXCLUDE_EXCEPTION_KEY_PATTERN = "^\\s*!"; /** * An exclude expression parsed with support for `!`-prefixed exception keys. */ export interface IParsedExcludeExpression { /** * Matches like {@link parse}, except that a path covered by an exception never matches. * When the expression has no exceptions, this is the result of {@link parse}. */ readonly matches: ParsedExpression; /** * Matches the exclude patterns only, ignoring exceptions. */ readonly matchesExclude: ParsedExpression; /** * The patterns of the enabled exceptions, see {@link getExcludeExceptions}. */ readonly exceptions: readonly string[]; /** * Whether the path or one of its parent folders matches an exception. Paths in version * control folders are not excepted, see {@link getFoldersSkippedByExcludeExceptions}. */ isExcepted(path: string, basename?: string): boolean; /** * Whether an exception could match a path below the folder, so that the * folder must be traversed even when it is excluded. Version control folders * are skipped, see {@link getFoldersSkippedByExcludeExceptions}. */ couldExceptionMatchBeneath(folderPath: string): boolean; } /** * Whether the key of an exclude expression is an exception, i.e. starts with `!`. */ export declare function isExcludeException(pattern: string): boolean; /** * Rewrites a pattern starting with `!` so that it matches a literal `!` * instead of being treated as an exclude exception. */ export declare function escapeExcludeException(pattern: string): string; /** * Returns the patterns, without the leading `!`, of the enabled exceptions of an exclude expression. Paths * matching an exception, and everything beneath them, are never excluded. Exceptions are relative to the * folder that is searched or shown, so absolute exceptions are ignored. */ export declare function getExcludeExceptions(expression: IExpression | undefined): string[]; /** * Returns the version control folders (such as `.git`) that exclude exceptions do not look into or re-include, * unless an exception names the folder, because they are large and rarely contain files to re-include. */ export declare function getFoldersSkippedByExcludeExceptions(exceptions: readonly string[]): string[]; /** * Returns a copy of the expression without exception keys, for consumers * that only understand plain exclude patterns. */ export declare function withoutExcludeExceptions(expression: IExpression): IExpression; /** * Parses an exclude expression that may contain `!`-prefixed exception keys. * A path is excluded when it matches an exclude pattern (or is below an excluded * folder) and neither the path nor one of its parent folders matches an exception. */ export declare function parseExcludeExpression(expression: IExpression, options?: IGlobOptions): IParsedExcludeExpression; /** * The exclude checks that a walk of a folder tree needs, for example an {@link IParsedExcludeExpression}. */ export interface IExcludeTreeEvaluator { matchesExclude(path: string, basename?: string, hasSibling?: (name: string) => boolean): unknown; isExcepted(path: string, basename?: string): boolean; couldExceptionMatchBeneath(folderPath: string): boolean; } export interface IExcludeTreeEntry { readonly path: string; readonly basename?: string; readonly isDirectory: boolean; /** * Whether the parent folder is excluded, as evaluated for the parent. */ readonly isParentExcluded: boolean; /** * Whether something besides the exclude patterns hides the entry, for example an ignore file. Exceptions override it too. */ readonly isHidden?: () => boolean; readonly hasSibling?: (name: string) => boolean; } /** * Evaluates an entry while walking a folder tree. It is excluded when it or its parent folder is excluded and no * exception matches it. It is visited when it is not excluded, or is a folder that an exception could match beneath. */ export declare function evaluateExcludeTreeEntry(evaluator: IExcludeTreeEvaluator, entry: IExcludeTreeEntry): { isExcluded: boolean; isVisited: boolean; }; export declare function isRelativePattern(obj: unknown): obj is IRelativePattern; export declare function getBasenameTerms(patternOrExpression: ParsedPattern | ParsedExpression): string[]; export declare function getPathTerms(patternOrExpression: ParsedPattern | ParsedExpression): string[]; export declare function patternsEquals(patternsA: Array | undefined, patternsB: Array | undefined): boolean; export {};